0

I dont know what to do. My tabulate function won't work for multiple eliminated candidates and multiple rounds of preferences. The rest is fine, as check50 states:

:) tabulate counts votes when all candidates remain in election :) tabulate counts votes when one candidate is eliminated :( tabulate counts votes when multiple candidates are eliminated tabulate function did not produce correct vote totals :( tabulate handles multiple rounds of preferences tabulate function did not produce correct vote totals

(I can't use the debugging feature either. It doesn't seem to work with programs that get input from the command line (argv). It won't show the variables in main, just 2 or 3 variables in functions (e.g. i and j from the loops). But that's another story -.-')

Might you take a look at my code? I know, I could blindly take some code from someone else, but I want to understand, what is missing in mine. Would really appreciate your help!

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

Greetings from Germany.

4
  • Welcome to CS50 StackExchange! What, specifically, isn't working? Are you getting an error from check50 or unexpected results from testing? Adding these details to your question will help us get you an answer quicker as we will have a better idea of what issue we are trying to solve. : ) – Robert S. Pratt Feb 7 at 21:32
  • Thanks for your answer. check50 states: :) tabulate counts votes when all candidates remain in election :) tabulate counts votes when one candidate is eliminated :( tabulate counts votes when multiple candidates are eliminated tabulate function did not produce correct vote totals :( tabulate handles multiple rounds of preferences tabulate function did not produce correct vote totals I've added it to the description. – c_dinosaur Feb 7 at 21:37
  • The debug50 story: when the debugger opens and stops at the breakpoint, go to the tab where prog is running and enter the election input. – DinoCoderSaurus Feb 8 at 3:00
  • Any other ideas, why my loop wont work for multiple eliminated candidates? – c_dinosaur Feb 12 at 15:44

You must log in to answer this question.

Browse other questions tagged .