From 9b83957b8c168b6e6db3c789fef4ca5049b72a59 Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Mon, 19 Feb 2024 21:38:27 +0000 Subject: Mon, Feb 19, 2024, 1:38 PM -08:00 --- wk3/pset/runoff/runoff.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'wk3') 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; } -- cgit v1.2.3