void tabulate(void)
    for (int i = 0; i < voter_count; i++) //as long as the number of total voters has not been met; this increases which voter we are on
        int j = 0;
        int plus1 = preferences[i][j]; //the integer plus1 is equal to the numerical equivalent of the candidate in voter's rank'th place
        if (candidates[plus1].eliminated == false) //if the candidate plus1 has not been eliminated
                candidates[plus1].votes++; //candidate plus1 gets a vote; need to exit out of this loop so i can increase
        else //in this situation, where the top candidate has been eliminated, we must change the rank
                int end = 0;
                for (j = 1; end != 1; j++) //as long as j is less than the number of total candidates availble for voting
                    plus1 = preferences[i][j];
                    if (candidates[plus1].eliminated == false) //if this candidate is valid
                        candidates[plus1].votes++; //then we can add to this voter
                        end++; //quits this loop
                    //in this situation, where the top candidate has been eliminated, the rank will again increase
    //once the previous voter is done, i aka voter increases so the next vote can be tabulated

Hello, I've been getting this error on my code. :( tabulate counts votes when multiple candidates are eliminated tabulate function did not produce correct vote totals

I've run debug 50 on it on a situation where there were two eliminations (4 candidates, 6 voters), and it seemed to work okay. Am I misinterpreting the mistake?

1 Answer 1


Actually your approach is very good to tabulate the vote count But,

Have you noticed, that you only should have to update the vote count for the candidates that has been preferred first rank, and how you can access the first preference?


preferences[i][j] is basically preferences[row][coloumn]

So, To count only first ranked candidates you should do,


Assign it to an int and then update the vote count of that candidate if candidate is not eliminated.

if candidate is eliminated, then be sure to move to the next highest rank i.e.

preferences[changing_row][next coloumn];

If you need any further assist, get back to me I will help you :)

To keep others answered too, be sure to tick the answer if I helped you :D

Here is a executable demo link: https://cee.studio/?bucket=200712-OyK&name=Oodep.RUvg

  • Thank you! I think I understand what you did, and I see that your program works, but I'm still a little lost. What happens if preferences[i][1] is also eliminated?
    – mushie2
    Jul 12, 2020 at 14:46
  • Oops..I think that's the corner case.You should be able to think about it but one thing don't get stuck there, use check50 to ensure the correctness of the code. Jul 12, 2020 at 16:18
  • Yeah, I was pretty stuck on that. I understand now, thank you!
    – mushie2
    Jul 12, 2020 at 21:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .