0

(I can't get formatting to work properly here so it might look a bit weird)

void tabulate(void) {

int j = 0;

for(int i = 0; i < candidate_count; i++)
{
    for( ; j < voter_count;)
    {
        //check candidate in position [i][j] in preferences table, if not eliminated then update vote total and move to next row
        if(candidates[preferences[i][j]].eliminated == false)
        {
            candidates[preferences[i][j]].votes++;
            j++;
        }

        //if candidate is eliminated move down one row and do not update vote total
        if(candidates[preferences[i][j]].eliminated == true)
        {
            j++;
        }
    }

    //reset j to zero to start from top of table again
    j = 0;
}
return;

}

To me, this makes sense, but it fails every test through check50 and gives candidates seemingly random vote values. If anyone can help me with this it would be very much appreciated, thanks.

(also all other parts of my code pass so I don't think it's a returning error from those)

1 Answer 1

0

For loops were around the wrong way, should have been < voter_count first, then < candidate_count second

You must log in to answer this question.

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