1

I keep getting these errors when running check50 on my runoff program:

print_winner prints name when someone has a majority print_winner did not print winner of election

print_winner returns true when someone has a majority print_winner did not print winner and then return true

I don't understand what the problem is since when I run my own tests it seems that my program does print out a candidate with the majority of votes! Does anyone know the metrics that check50 is using for print winner I would like to test that out myself? otherwise, this is my code:

// Print the winner of the election, if there is one
bool print_winner(void)
{
    int majority = round((float) voter_count / 2);
    bool winner = false;
    for (int i = 0; i < candidate_count; i++)
    {

        // if any candidate has more then half of the votes (majority) print out their name and return true
        if (candidates[i].votes > majority)
        {
            printf("%s \n", candidates[i].name);
            winner = true;
        }
    }
    return winner;

All of the other program requirements are good.

  • Try taking the space out of the output here printf("%s \n", candidates[i].name);. I know that it's not specified in the spec (which it commonly is), but historically speaking, check50 is looking for an "exact match" of some kind. – DinoCoderSaurus Jan 15 at 12:26
  • Thanks, no errors now! i will keep this in mind – rassenguy Jan 15 at 14:19
0
int majority = round((float) voter_count / 2);

Make sure that majority is calculated correctly. Right now you're only computing half of the voters.

Also, why are you casting to float ?

| improve this answer | |

You must log in to answer this question.

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