diff options
author | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-02-19 21:38:27 +0000 |
---|---|---|
committer | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-02-19 21:38:27 +0000 |
commit | 9b83957b8c168b6e6db3c789fef4ca5049b72a59 (patch) | |
tree | 1fb848853405771dc5e50fe7ed0b3f7f887834b4 /wk3/pset/runoff | |
parent | 940e8355fadc164d3895a17cd91487878ff4000d (diff) |
Mon, Feb 19, 2024, 1:38 PM -08:00
Diffstat (limited to 'wk3/pset/runoff')
-rw-r--r-- | wk3/pset/runoff/runoff.c | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/wk3/pset/runoff/runoff.c b/wk3/pset/runoff/runoff.c index 9f08058..b727f59 100644 --- a/wk3/pset/runoff/runoff.c +++ b/wk3/pset/runoff/runoff.c @@ -164,13 +164,6 @@ void tabulate(void) // Print the winner of the election, if there is one bool print_winner(void) { - int dead[candidate_count]; - dead[0] = 0; - // set the unused spaces of the array of least voted - for (int j = 1; j < candidate_count; j++) - { - dead[j] = -1; - } for (int i = 0; i < candidate_count; i++) { if (candidates[i].votes >= (voter_count / 2)) @@ -178,16 +171,6 @@ bool print_winner(void) printf("%s", candidate.name); return true; } - else if (candidates[dead[0]].votes > candidates[i].votes) // if the new candidate has more less than previous - { - // clear the list of dead - for (int j = 1; j < candidate_count; j++) - { - dead[j] = -1; - } - // put it at the start of the new list - dead[0] = i; - } } return false; } @@ -195,7 +178,16 @@ bool print_winner(void) // Return the minimum number of votes any remaining candidate has int find_min(void) { - // TODO + if (candidates[dead[0]].votes > candidates[i].votes) // if the new candidate has more less than previous + { + // clear the list of dead + for (int j = 1; j < candidate_count; j++) + { + dead[j] = -1; + } + // put it at the start of the new list + dead[0] = i; + } return 0; } |