From 41305528e75880ac1cd0025f53f831104817edb5 Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Mon, 19 Feb 2024 21:57:23 +0000 Subject: Mon, Feb 19, 2024, 1:57 PM -08:00 --- wk3/pset/runoff/runoff.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/wk3/pset/runoff/runoff.c b/wk3/pset/runoff/runoff.c index 9ff4d19..17b4bf2 100644 --- a/wk3/pset/runoff/runoff.c +++ b/wk3/pset/runoff/runoff.c @@ -187,7 +187,8 @@ int find_min(void) // look through all candidates for (int i = 0; i < candidate_count; i++) { - if (!candidates[i].eliminated) { + if (!candidates[i].eliminated) + { // if the new candidate has less votes than previous if (candidates[i].votes < candidates[dead[0]].votes) { @@ -207,13 +208,29 @@ int find_min(void) // Return true if the election is tied between all candidates, false otherwise bool is_tie(int min) { - // TODO - return false; + for (int i = 0; i < candidate_count; i++) + { + if (!candidates[i].eliminated) + { + if (candidates[i].votes != min) { + return false; + } + } + } + return true; } // Eliminate the candidate (or candidates) in last place void eliminate(int min) { - // TODO + for (int i = 0; i < candidate_count; i++) + { + if (!candidates[i].eliminated) + { + if (candidates[i].votes == min) { + candidates[i].eliminated = true; + } + } + } return; } -- cgit v1.2.3