One problem I see:
In tabulate() for(int i = 0; i > voter_count; i++)
I think you meant to write
i < voter_count
because otherwise it will not enter the loop since your condition will turn out to be 0 > 2
The same holds true for the next loop as well: for (int j = 0; j > candidate_count; j++)
. Here too, change j > candidate_count
to j < candidate_count
to enter the loop.
You can revisit the problem after this first step.
Update in response to comment:
I don’t think tabulate() is giving the same result. After you have made the correction from >
to <
you will find that vote is incremented. You may want to verify this by using debug50.
The next problem I see is that it appears to return immediately after incrementing the votes count (just once perhaps):-
candidates[preferences[i][j]].votes++;
return;
Another observation in:
In vote() is that break
will not get executed since it is after the return
:-
preferences[voter][rank] = i;
return true;
break;
I’mI am only trying to get you one step forward and you might want to use the debugger. It can provide you information for every iteration much better than I can in an answer here.
Also, personally, I find it useful to manually execute each iteration and note down the value of the variable as I go along.