0

my tabulate function is storing votes from the preferences array, but problem arising when multiple candidates are eliminated check50 shows error there. Please help me with this, and tell me what is going on under the hood with multiple candidates, also how can I debug this problem myself in debug50? I will really appreciate your help, TIA

:) 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

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

        candidates[preferences[i][j]].votes++;
    }
}
1

The int j = 0; would have to go into the loop, as you want to start at 0 for each voter. If you fix the other part and don't reset it, and j keeps growing, you might run into segmentation faults.

So your if triggers, and you advance to the second candidate on the list. But what then, what if that one has been eliminated as well? You would need some kind of inner loop.

| improve this answer | |

You must log in to answer this question.

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