I tried the following idea to print winner function. Can you check why it is not working?
Defined a function named find_majority. This is to get around the float problem.
called the function and assigned the value to the majority.
Use this variable in the print winner function
Find majority function
' int find_majority( voter_count) { int winning_votes; if(voter_count%2==0) { winning_votes = voter_count / 2; return winning_votes;
}
else
{
int temp_winning_votes= voter_count + 1;
winning_votes = temp_winning_votes/2;
return winning_votes;
}
} '
- Calling the function
'majority = find_majority();'
- using the variable
' // Print the winner of the election, if there is one bool print_winner(void) {
for (int i=0; i<candidate_count; i++)
{
if(candidates[i].votes>majority)
{
printf("%s\n",candidates[i].name);
return true;
}
}
return false;
} '