The way I have coded it, I believe my min should be set correctly, but when I try to run it, the check50 says it's wrong. I tested it by printing my min at various points in the code, and it is not givng the right min. Any advice why? Thanks!
// Return the minimum number of votes any remaining candidate has int find_min(void) { // TODO int min = voter_count; for (int i = 0; i < candidate_count; i++) { if (candidates[i].eliminated == false && candidates[i].votes < min) { min = candidates[i].votes; printf("min %s is %i\n", candidates[i].name, min); //just to see where going wrong } printf("final min is %i\n", min); //just to see where going wrong return min; } return 0; }
This is what I got when I ran the program, so clearly something is going wrong. ~/pset3/runoff/ $ ./runoff a b c Number of voters: 9 Rank 1: a Rank 2: b Rank 3: c
Rank 1: a Rank 2: c Rank 3: b
Rank 1: a Rank 2: b Rank 3: c
Rank 1: a Rank 2: b Rank 3: c
Rank 1: c Rank 2: b Rank 3: a
Rank 1: c Rank 2: a Rank 3: b
Rank 1: c Rank 2: a Rank 3: b
Rank 1: b Rank 2: c Rank 3: a
Rank 1: c Rank 2: b Rank 3: a
min a is 4 final min is 4 a b c