Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool vote(string name)
- {
- for (int i = 0; i < candidate_count; i++)
- {
- //If candidate has been found in candidate array
- if (strcmp(candidates[i].name, name) == 0)
- {
- candidates[i].votes++;
- return true;
- }
- }
- //No candidate found
- return false;
- }
- // Print the winner (or winners) of the election
- void print_winner(void)
- {
- int leadertally = 0;
- //get the highest vote
- for (int i = 0; i < candidate_count; i++)
- {
- if (candidates[i].votes > leadertally)
- {
- leadertally += candidates[i].votes;
- }
- }
- //print the highest candidate(s)
- for (int j = 0; j < candidate_count; j++)
- {
- if (candidates[j].votes == leadertally)
- {
- printf("%s\n", candidates[j].name);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement