0

I'm having a hard time seeing where I went wrong with my two functions IS_TIE and PRINT_WINNER when I put my code through check50, for print_winner I get: "did not print winner of election" and "did not print winner of election and then return true" for is_tie I get: "did not return false"

code is as follows


bool print_winner(void)
{
    // TODO
    for (int i = 0; i < candidate_count; i++)
    {
        if (!candidates[i].eliminated && candidates[i].votes > voter_count / 2)
        {
            printf("%s Wins!\n", candidates[i].name);
            return true;
        }
    }
    return false;
}


bool is_tie(int min)
{
    // TODO
    for (int i = 0; i < candidate_count; i++)
    {
        if (!candidates[i].eliminated && candidates[i].votes == min)
        {
            return true;
        }
    }
    return false;
}

1 Answer 1

0

print_winner does not produce the specified output:

If any candidate has more than half of the vote, their name should be printed and the function should return true

No baloons and confetti (ie no "Wins!"). The tester is comparing the output to the expected output. The expected output is the candidate name.

is_tie returns true when it encounters the first candidate that has min votes. It needs to either evaluate all the candidates before it can determine a tie or find a candidate that does not have min votes.

1
  • oh, that makes more sense. thank you!
    – faeyb
    Commented Oct 21, 2023 at 16:59

You must log in to answer this question.

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