I am doing the 2020 version of CS50's pset3 and I am already stuck (again) at the runoff voter function. My code below resulted in segmentation fault. I don't know how to fix this though.
So here's my code (Let me know if this is not enough info, I only showed my code so far as the whole code is very long):
bool vote(int voter, int rank, string name)
{
// TODO
// Assume that the name is not yet given and update if a name is given
bool name_exist = false;
//Look for a candidate called name
for (int i = 0; i <= candidate_count ; i++)
{
//If the input matches a candidate list update the preference
{
for (int j = 0; j < i ; j++)
{
if (strcmp(candidates[i].name, name) == 0)
{
preferences[voter][rank] = candidate_count;
printf("%s\n",name);
}
}
name_exist = true;
}
}
return name_exist;
Anybody can provide some idea or suggestions? Thanks.