modernkilla82

Untitled

Apr 14th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. //*********************************************
  2. //** Written by..: Jason Bonomo
  3. //** Date Written: April 14, 2019
  4. //** Assignment.....: Exam Four: The Election
  5. //*********************************************
  6. #define _CRT_SECURE_NO_WARNINGS
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #define PAUSE system("pause")
  10. #define CLS system("cls")
  11. #define FLUSH myFlush();
  12. //Array Size
  13. #define SIZE 49
  14. //Flush
  15. void myFlush() {
  16. while (getchar() != '\n');
  17. }
  18.  
  19. void displayMenu() {
  20. CLS;
  21. printf(" The Election \n", 'N');
  22. printf("1. Vote for Ivanka Trump \n");
  23. printf("2. Vote for Michelle Obama \n");
  24. printf("3. Candidate Specific Votes \n");
  25. printf("4. Display Total Votes for each candidate \n");
  26. printf("5. All votes in order \n");
  27. printf("6. Quit\n\n");
  28. printf("Make a selection: ");
  29. }
  30.  
  31. char getChoice() {
  32. char result;
  33. displayMenu();
  34. scanf("%c", &result);
  35. return toupper(result);
  36. }
  37.  
  38. void displayMessage(char string[], char);
  39. void displayMenu();
  40. char getChoice();
  41. void myFlush();
  42.  
  43. main() {
  44. int ivankaVotes = 0;
  45. int michelleVotes = 0;
  46. int totalVotes = 0;
  47. int state = 0;
  48. int candidateChoice;
  49. int StatesArray[SIZE];
  50.  
  51. char userChoice = ' ';
  52.  
  53. do {
  54. userChoice = getChoice();
  55. switch(userChoice) {
  56. //Enter Votes for Ivanka Trump >Works
  57. case '1':
  58. printf("You have voted for Ivanka Trump from the state of %d \n", state);
  59. ivankaVotes++;
  60. PAUSE;
  61. break;
  62. //Enter Votes for Michele Obama >Works
  63. case '2':
  64. printf("You have voted for Michele Obama from the state of %d \n", state);
  65. michelleVotes++;
  66. PAUSE;
  67. break;
  68. //Candidate specific view total >Works
  69. case '3':
  70. printf("Please select which candidate you would like to view the votes for! \n");
  71. printf("1. Ivanka Trump \n");
  72. printf("2. Michelle Obama \n");
  73. scanf("%i \n", &candidateChoice);
  74. if (candidateChoice == 2) {
  75. printf("Showing votes for Michelle Obama! \n");
  76. printf("%d \n", michelleVotes);
  77. } else {
  78. printf("Showing votes for Ivanka Trump! \n");
  79. printf("%d \n", ivankaVotes);
  80. };
  81. PAUSE;
  82. break;
  83. //Total Votes for Each Candidate
  84. case '4':
  85. printf("Total votes for Ivanka Trump: %d \n", ivankaVotes);
  86. printf("Total votes for Michelle Obama: %d \n", michelleVotes);
  87. PAUSE;
  88. break;
  89. //All Votes for Each Candidate in order - YOU CAN DO THIS :) >NO I CANT REEEEEEEEEEEEEEEEEEEEEEEEEEEE
  90. case '5':
  91. printf("REEEE \n");
  92. PAUSE;
  93. break;
  94. //Display Quit Option >Works
  95. case '6':
  96. printf("You have Quit the program! :( \n");
  97. break;
  98. default:
  99. printf("You must pick a choice from the menu! \n");
  100. PAUSE;
  101. break;
  102.  
  103. }
  104. } while (userChoice != '6');
  105.  
  106. PAUSE;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment