0

My could does not produce the correct voter count when multiple voters are eliminates.

// Tabulate votes for non-eliminated candidates
void tabulate(void)
{
    int j = 0;
    // Iterate over voters
    for(int i = 0; i < voter_count; i++)
    {
        // Check for eliminated candidates and iterate 
        for (;candidates[preferences[i][j]].eliminated == true;)
        {
            j++;
        }

        // Update vote count
        candidates[preferences[i][j]].votes++;
    }
    return;
}

So according to me this code should start off both i and j at 0. Then iterate over voters [i] then check if the preference candidate has been eliminated if he has then j++ therefore checking his next rank iterate over that until candidate is not eliminated (false) then update the vote count

Where did I go wrong?

0

You would have to set j to 0 inside the outer loop, before you begin your inner loop (which I would make a while loop), so it resets for each voter.

| improve this answer | |

You must log in to answer this question.

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