From 8162924303d9ecc554da52782e70f0425d51d2a7 Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Mon, 19 Feb 2024 21:33:03 +0000 Subject: Mon, Feb 19, 2024, 1:33 PM -08:00 --- wk3/pset/runoff/runoff.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/wk3/pset/runoff/runoff.c b/wk3/pset/runoff/runoff.c index f3e31b2..b218642 100644 --- a/wk3/pset/runoff/runoff.c +++ b/wk3/pset/runoff/runoff.c @@ -176,16 +176,32 @@ bool print_winner(void) */ /* - for (int i = 0; i < candidate_count; ) + 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++) { - if (candidates.votes >= (voter_count / 2)) + dead[j] = -1; + } + for (int i = 0; i < candidate_count; i++) + { + if (candidates[i].votes >= (voter_count / 2)) { printf("%s", candidate.name); return true; } else if () { - + if (candidates[winners[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; + } + // put it at the start of the new list + winners[0] = i; + } } } */ -- cgit v1.2.3