bool print_winner(void)
{
int others = 0;
for (int i = 0; i < candidate_count; i++)
{
int h = others < candidate_count;
if(candidates[i].votes > candidates[h].votes
{
printf("%s\n", candidates[i].name);
return true;
}
}
return false;
} ``
-
candidates
comes from this struct:typedef struct { string name; int votes; bool eliminated; }
candidate;
what i want to do in the function is print the name of the candidate with the most votes (the majority). however when i compile the program, nothing would be printed. i have also created this function to 'eliminate' candidates, so it is possible that the error may be from there:
void tabulate(void)
{
int others = 0;
for(int i = 0; i<candidate_count; i++)
{
int h = others < candidate_count;
if(candidates[i].votes < candidates[h].votes)
{
//eliminate candidates[i].votes
candidates[i].eliminated = true;
}
}
return;
}
*when i compile my program nothing seems to be wrong.
Aucun commentaire:
Enregistrer un commentaire