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.