I'm having trouble understanding how to write this vote function. I understand what I wrote is incorrect because I am assigning a struct to an array of ints but I can't understand how I'm supposed to tell preferences that candidates[i] is the voters choice.
bool vote(int voter, int rank, string name)
{
// Loop over size of candidate list
for (int i = 0; i < candidate_count; i++)
{
// Compare two strings (strcmp returns 0 if there's a match)
if(strcmp(name, candidates[i].name) == 0)
{
preferences[voter][rank] = candidates[i];
return true;
}
}
return false;
}
error: assigning to 'int' from incompatible type 'candidate' preferences[voter][rank] = candidates[i];
The only int in the candidate struct is votes which I don't think is useful for understanding which candidate was picked.
preferences[voter][rank] = candidates[i].votes;
I'd appreciate any help in understanding the intuition behind this problem. Thank you!