2

The error means a path that does not take the if branch or the else branch will not return a boolean, since the returns are embedded in those blocks. Think about this comment //if input name does not match with any name . What the program is doing is //if input name does not match this name . If program returns on the first non-matching name, it will not ...


1

Try an election with 3 candidates, A B C, and 6 voters, with the result A 3, B 1, C 2. The self-evident winner is A with 3 votes. The first print_winner function will return C. On the first iteration of i, winner_votes will be 3. However, on the second iteration, where i equals 1, it will only compare B to C, and winner_votes will be 2. Since the inner (j) ...


1

Try this election: 3 candidates: a, b, c and 2 voters who vote for c. It reports a and b as (tied) winners. That's because c's votes are not considered in the first for (int i = 0; i < voter_count; i++), because voter_count is 2 and candidate c is index 2. (Neither is candidate c considered in the second for (int i = 0; i < voter_count; i++), for the ...


1

https://cs50.stackexchange.com/a/38819/25714 Check this post on seg fault (plurality) that I have answered. If found to help be sure to tick the answer to keep other smiling too 😃


Only top voted, non community-wiki answers of a minimum length are eligible