0

I've been trying to solve the new problem set 3 plurality step by step, and here where I got stuck, but somehow I'm sure about my answer

bool vote(string name)
{
bool v = false

for (int i = 0 ; i < candidate_count ; i++)
{
    if (strcmp( candidates[i].name , name ) == 0)
    {
        candidates[i].votes += 1;
        v = true ;
        break ;
    }

}
return v ;}

when I run the program

~/pset3/plurality/ $ ./plurality sara zack eric

Number of voters: 1

Vote: sara

Invalid vote.

  • is program compiled? This bool v = false looks like it should give error on compile. – DinoCoderSaurus Jan 18 at 17:48
2

If you fix the missing semicolon that @DinoCoderSaurus mentioned, this works fine. I suspect you hadn't compiled it after writing your function, so the default return false was still being used.

| improve this answer | |
  • I feel bad for that mistake, thank you it worked !! ;) – reham501 Feb 3 at 21:11

You must log in to answer this question.

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