0

I ran check50 and got the following errors:

running clang plurality.c -o plurality -std=c11 -ggdb -lm -lcs50... plurality.c:71:29: error: expected expression for (int i = 0; i < int voter_count; i++) ^ plurality.c:87:13: error: expected expression if (float(candidates[i].votes / voter_count) * 100 > 50) ^ 2 errors generated.

EDIT: I just caught another error as I got it wrong when someone is a winner. I will work on that but I think the above errors are not connected to this. It's my first post here and happy for every hint I get, even how to improve asking for help

MY CODE LOOKS LIKE THIS:

bool vote(string name)
{
        for (int i = 0; i < int voter_count; i++)
        {
            if (name == candidates[i].name)
            {
                candidates[i].votes += 1;
                printf("Vote: %s\n", name);
                return true;
            }
        }
        return false;
}
// Calculate who has majority and print the winner (or winners) of the election
void print_winner(void)
{
    for (int i = 0; i < candidate_count; i++)
    {
        if (float(candidates[i].votes / voter_count) * 100 > 50)
        {
            printf("%s\n", candidates[i].name);
        }
    }
}

I have fixed most of the other errors but this one I just can't make sense of. Is it a semantic or a logical error? Can someone help? Thanks!

1

when casting data types, the cast keyword, in this case float, needs to be enclosed in parentheses.

    if( (float)...)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |
  • Oh, ok, thanks so much! I didn't know. – user28381 May 31 at 14:54

You must log in to answer this question.

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