diff options
author | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-02-19 20:35:15 +0000 |
---|---|---|
committer | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-02-19 20:35:15 +0000 |
commit | 531d50b7f3b8b3f8920e2bfbdd6187c49fcda83f (patch) | |
tree | b4b9ad1d1755c1c3011ea294acf440ee86cf5b29 /wk3/pset/runoff/runoff.c | |
parent | 2283149f9995c02124ab12c30bb52bf2dfba1afb (diff) |
Mon, Feb 19, 2024, 12:35 PM -08:00
Diffstat (limited to 'wk3/pset/runoff/runoff.c')
-rw-r--r-- | wk3/pset/runoff/runoff.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/wk3/pset/runoff/runoff.c b/wk3/pset/runoff/runoff.c index 5ed853e..2d421f3 100644 --- a/wk3/pset/runoff/runoff.c +++ b/wk3/pset/runoff/runoff.c @@ -164,33 +164,33 @@ void tabulate(void) // Print the winner of the election, if there is one bool print_winner(void) { - int winners[candidate_count]; - winners[0] = 0; + int losers[candidate_count]; + losers[0] = 0; // reset it for (int j = 1; j < candidate_count; j++) { - winners[j] = -1; + losers[j] = -1; } // goes through every candidate, looks at votes, eliminates the least voted for (int i = 1; i < candidate_count; i++) { - if (candidates[winners[0]].votes < candidates[i].votes) // if the new candidate has more votes than previous + if (candidates[losers[0]].votes > candidates[i].votes) // if the new candidate has more votes than previous { // clear the list of winners for (int j = 1; j < candidate_count; j++) { - winners[j] = -1; + losers[j] = -1; } // put it at the start of the new list - winners[0] = i; + losers[0] = i; } - else if (candidates[winners[0]].votes == candidates[i].votes) + else if (candidates[losers[0]].votes == candidates[i].votes) { for (int j = 1; j < candidate_count; j++) { - if (winners[j] == -1) + if (losers[j] == -1) { - winners[j] = j; + losers[j] = j; break; } } |