0

when I try my code manually it does everything correct, but when I run Check 50, it says following ":( print_winner identifies Alice as winner of election print_winner function did not print winner of election" void print_winner(void) { // Get the highest scores merge_sort(candidates, candidate_count); // Print votes int i = candidate_count - 1; do { printf("%s\n", candidates[i].name); i--; } while (candidates[i].votes == candidates[i + 1].votes); return; }

Where it says merge_sort is just a code for sorting being the highest number of the array the highest amount of votes. Thanks in advance for any help

1 Answer 1

0

I am not sure which version of voting you are implementing. Having the highest number of votes is not enough to be considered a winner (at least in the runoff version).

The winner needs to have more than half of all votes. will have candidates[i].votes > (voter_count / 2)

Also be careful with sorting the array - it looks like you might be modifying the original candidates[] array, which potentially may lead to some problems. Perhaps sort a copy of that array to make sure you preserve the original one?

You must log in to answer this question.

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