1

The print_winner function must find the candidate who has the highest votes and print its name. In case there are two candidates who have the same number of votes, the function must print 2 names.

Here are the errors

:( print_winner identifies Alice as winner of election
    print_winner function did not print winner of election
:( print_winner identifies Bob as winner of election
    print_winner function did not print winner of election
:( print_winner identifies Charlie as winner of election
    print_winner function did not print winner of election
:( print_winner prints multiple winners in case of tie
    print_winner function did not print both winners of election
:( print_winner prints all names when all candidates are tied
    print_winner function did not print all three winners of election

Here is my function code

void print_winner(void)
{
    int maxx;
    maxx = candidates[0].votes;
    for (int i = 1; i < candidate_count; i++)
    {
        if(maxx < candidates[i].votes)
        {
            maxx = candidates[i].votes;
        }
    }
    for (int j = 0; j < candidate_count; j++)
    {
        if (candidates[j].votes == maxx)
        {
            printf("%s \n", candidates[j].name);
        }
    }
}
Vahram
  • 11
  • 2

1 Answers1

0

From the spec

The function should print out the name of the candidate who received the most votes in the election, and then print a newline.

This printf("%s \n", candidates[j].name); prints the name of the candidate, a space, then a newline. It may seem like an insignificant difference, in fact undetectable by human eye, but check50 does not find an exact match of the expected output.

DinoCoderSaurus
  • 6,110
  • 2
  • 10
  • 15