// Print the winner (or winners) of the election void print_winner(void) { int max =0; for(int i=0; i<candidate_count; i++) { if(candidates[i].votes>candidates[i+1].votes) { max=candidates[i].votes; } else if (candidates[i].votes==max) { printf("%s\n, winner ", candidates[i].name); }



this is my code to print the winner but it is not working, can someone help and tell me where I have gone wrong. The output i get is this-

./plurality bob charlie Number of voters: 2 Vote: bob Vote: bob

For some reason the print statement doesn't get executed. Would really appreciate anyone who could guide me, have been stuck on this for a while. Thank you in advance!


When You are using else if It executes either of the statements. Remove else if statement . Make another loop(Independent of the previous loop) and then print the name of candidate if it has maximum votes.

  • 1
    Thanks a lot! @MWD
    – user01
    Nov 5 '21 at 6:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .