0

When inputting vote names in "Plurality", the programme is returning Invalid vote. It looks like this in the terminal:

./plurality Alice Bob Garry Jim
Number of votes: 4
Vote: Alice
Invalid vote

Within the code, I think this is in this section:

for (int i = 0; i < voter_count; i++)
    {
        string name = get_string("Vote: ");

        // Check for invalid vote
        if (!vote(name))
        {
            printf("Invalid vote.\n");
        }
    }

I don't understand what's going on because, in the above example, Alice is a valid input, right? And yet the programme tells me it's invalid. It's particularly confusing as this is the code supplied by the course (students don't compose or change this code; the work on subfunctions in this assignment).

If I remove the ! before vote(name) the programme functions (which seems to indicate the problem is here), although, obviously, it now won't catch if an invalid vote is entered.

0

The problem is not in the supplied distro code. The problem is in the vote function in this program.

This block if (!vote(name))says "If the returned value from the vote function is false, then the name supplied is an "invalid vote".

You must log in to answer this question.

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