Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*********************************************
- //** Written by..: Jason Bonomo
- //** Date Written: April 14, 2019
- //** Assignment.....: Exam Four: The Election
- //*********************************************
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #define PAUSE system("pause")
- #define CLS system("cls")
- #define FLUSH myFlush();
- //Array Size
- #define SIZE 49
- //Flush
- void myFlush() {
- while (getchar() != '\n');
- }
- void displayMenu() {
- CLS;
- printf(" The Election \n", 'N');
- printf("1. Vote for Ivanka Trump \n");
- printf("2. Vote for Michelle Obama \n");
- printf("3. Candidate Specific Votes \n");
- printf("4. Display Total Votes for each candidate \n");
- printf("5. All votes in order \n");
- printf("6. Quit\n\n");
- printf("Make a selection: ");
- }
- char getChoice() {
- char result;
- displayMenu();
- scanf("%c", &result);
- return toupper(result);
- }
- void displayMessage(char string[], char);
- void displayMenu();
- char getChoice();
- void myFlush();
- main() {
- int ivankaVotes = 0;
- int michelleVotes = 0;
- int totalVotes = 0;
- int state = 0;
- int candidateChoice;
- int StatesArray[SIZE];
- char userChoice = ' ';
- do {
- userChoice = getChoice();
- switch(userChoice) {
- //Enter Votes for Ivanka Trump >Works
- case '1':
- printf("You have voted for Ivanka Trump from the state of %d \n", state);
- ivankaVotes++;
- PAUSE;
- break;
- //Enter Votes for Michele Obama >Works
- case '2':
- printf("You have voted for Michele Obama from the state of %d \n", state);
- michelleVotes++;
- PAUSE;
- break;
- //Candidate specific view total >Works
- case '3':
- printf("Please select which candidate you would like to view the votes for! \n");
- printf("1. Ivanka Trump \n");
- printf("2. Michelle Obama \n");
- scanf("%i \n", &candidateChoice);
- if (candidateChoice == 2) {
- printf("Showing votes for Michelle Obama! \n");
- printf("%d \n", michelleVotes);
- } else {
- printf("Showing votes for Ivanka Trump! \n");
- printf("%d \n", ivankaVotes);
- };
- PAUSE;
- break;
- //Total Votes for Each Candidate
- case '4':
- printf("Total votes for Ivanka Trump: %d \n", ivankaVotes);
- printf("Total votes for Michelle Obama: %d \n", michelleVotes);
- PAUSE;
- break;
- //All Votes for Each Candidate in order - YOU CAN DO THIS :) >NO I CANT REEEEEEEEEEEEEEEEEEEEEEEEEEEE
- case '5':
- printf("REEEE \n");
- PAUSE;
- break;
- //Display Quit Option >Works
- case '6':
- printf("You have Quit the program! :( \n");
- break;
- default:
- printf("You must pick a choice from the menu! \n");
- PAUSE;
- break;
- }
- } while (userChoice != '6');
- PAUSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment