diff options
author | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-02-19 02:46:47 +0000 |
---|---|---|
committer | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-02-19 02:46:47 +0000 |
commit | 2ffc523b74ec5b68a06cbf9018badb0f7e91e535 (patch) | |
tree | 89f97e45d89b9f60e2be4208fb46b197d8cc5003 /wk3/pset | |
parent | 13bdbe1d9a3665e92ccf3ef3dbd0bb300607356d (diff) |
Sun, Feb 18, 2024, 6:46 PM -08:00
Diffstat (limited to 'wk3/pset')
-rw-r--r-- | wk3/pset/plurality/plurality.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/wk3/pset/plurality/plurality.c b/wk3/pset/plurality/plurality.c index ad6a487..1284cfa 100644 --- a/wk3/pset/plurality/plurality.c +++ b/wk3/pset/plurality/plurality.c @@ -67,7 +67,8 @@ bool vote(string name) { for (int i = 0; i < candidate_count; i++) { - if (name == candidates[i].name) { + if (name == candidates[i].name) + { candidates[i].votes++; return true; } @@ -78,10 +79,18 @@ bool vote(string name) // Print the winner (or winners) of the election void print_winner(void) { - string winners[candidate_count - 1] = candidates[0]; - for (int i = 1; i < candidate_count - 1; i++) { - if (winners[0] < candidate[i].name) { + string winners[candidate_count - 1]; + winners[0] = candidates[0].name; + for (int i = 1; i < candidate_count - 1; i++) + { + if (winners[0] < candidates[i].name) + { + for (int j = 1; j < candidate_count - 1; j++) + { + winners[j] = 0; + } + winners[0] = candidates[i].name; } } return; |