0

So I have been working on the tabulate function and Check50 says that the function is correct and it does properly work when no candidate is eliminated and when one is eliminated, but not when multiple are.

Anyone know why?

void tabulate(void)
{
    for (int i = 0; i < voter_count; i++)
    {
        for (int j = 0; j < candidate_count; j++)        
        {    
            if (candidates[j].eliminated == false)
            {
                candidates[preferences[i][j]].votes++;
                j = candidate_count;
            }
    
        }

    }
}
0

If you look at the error messages, it also shows this: :( tabulate handles multiple rounds of preferences tabulate function did not produce correct vote totals

I solved the problem set a while back. The main difference between my code and yours, which is causing the problem, is this: if (candidates[j].eliminated == false). Instead of just checking if candidate[j] itself is eliminated, try using the voters candidate preferences so that it checks if the voters preference is eliminated. This way it will be able to handle multiple eliminations and will produce the correct vote totals. Hope that helps!

You must log in to answer this question.

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