0

I have been stuck at the tabulate function for quite some time, I'm able to code all the other functions except for this tabulate functions.

If possible do help me look to see what wrong with the tabulate function. The logic that I have used is all commented within the code itself.

Your help is much appreciated thank you!

void tabulate(void)
{
    for (int b = 0 ; b < voter_count ; b++)
    {
        for (int c = 0 ; c < candidate_count ; c++)
        {
            //if candidates name corresponds to that of the preferences index
            if (strcmp(candidates[c].name, candidates[preferences[b][c]].name) == 0)
            {
                //if the candidate is not eliminated
                if (candidates[c].eliminated == false)
                {
                    //+1 vote count to the candidate
                    candidates[c].votes++;
                }
                //if the candidate is eliminated
                else 
                {
                    //skip to the next iteration of the loop and move on to the next preference of the voter
                    continue;
                }
            }
        }
    }
    return;
}

1 Answer 1

0

candidate[c] is not the same thing as preferences[b][c].

Think about a runoff among candidates A, B, C where the first voter casts the ballot C, B, A. When c is 0, candidate[0].name is A. But preferences[0][0].name is C (the first voter's first preference).

That will cause problems wherever candidates[c] is used.

You must log in to answer this question.

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