0

// CODE 1 :-

bool vote(string name) { // TODO for (int i = 0; i < candidate_count; i++) { if ( candidates[i].name == name ) { candidates[i].votes = candidates[i].votes + 1 ; return true ;

    }
}

return false;

}

// CODE 2 :-

bool vote(string name) { // TODO for (int i = 0; i < candidate_count; i++) { if (strcmp( candidates[i].name, name) == 0) { candidates[i].votes = candidates[i].votes + 1 ; return true ;

    }
}

return false;

}

1 Answer 1

0

You can't compare the values of strings with ==. The reason for this is explained in detail in Week 4, but for now, when you use == with strings, it isn't comparing the value of those two strings.

You must log in to answer this question.

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