I don't understand what's going on with the solutions to the voter preference and tabulate functions. I had set up a similar function to the answer with the exception that I had
[voter][i] = rank;
Because I thought that the index for the candidate would be the same index for the voter preference and we would put the rank as the actual element in that spot. So candidate 0 would have whatever rank they were given when the voter puts it in.
But the code here has it inversed.
preferences[voter][rank] = i;
So I'm really stuck on the logic here. If we start with candidate 0 and the name matches, then we would set the rank equal to 0 for that candidate preference? What if the voter is 0 and they rank candidate zero at 3 and then we set it equal to 0 to match the candidate, what is happening? Is the rank actually an index so that a rank of 3 is the array position and then the candidate index is the value we put in the array?
bool vote(int voter, int rank, string name)
{
for(int i = 0; i<candidate_count;i++)
{
if(strcmp(candidates[i].name, name) == 0) //do these match thats all
{
preferences[voter][rank] = i;
return true;
}
}
return false;
}