From 47db1ae381bf4299e81238464defbbd419d1f876 Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Mon, 19 Feb 2024 05:01:43 +0000 Subject: Sun, Feb 18, 2024, 9:01 PM -08:00 --- wk3/pset/plurality/plurality.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'wk3') diff --git a/wk3/pset/plurality/plurality.c b/wk3/pset/plurality/plurality.c index 53b66d3..f4fb3c2 100644 --- a/wk3/pset/plurality/plurality.c +++ b/wk3/pset/plurality/plurality.c @@ -80,10 +80,10 @@ bool vote(string name) void print_winner(void) { string winners[candidate_count]; - winners[0] = candidates[0].votes; + winners[0] = 0; for (int i = 1; i < candidate_count; i++) { - if (winners[0] < candidates[i].votes) // if the new candidate has more votes than all previous + 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++) @@ -91,9 +91,9 @@ void print_winner(void) winners[j] = 0; } // put it at the start of the new list - winners[0] = candidates[i].votes; + winners[0] = i; } - else if (winners[0] == candidates[i].votes) + else if (candidates[winners[0]].votes == candidates[i].votes) { for (int j = 1; j < candidate_count; j++) { -- cgit v1.2.3