modernkilla82

Untitled

Apr 14th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.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. Average number of votes \n");
  28. printf("7. Quit\n\n");
  29. printf("Make a selection: ");
  30. }
  31.  
  32. char getChoice() {
  33. char result;
  34. displayMenu();
  35. scanf("%c", &result);
  36. return toupper(result);
  37. }
  38.  
  39. void displayMessage(char string[], char);
  40. void displayMenu();
  41. char getChoice();
  42. void myFlush();
  43.  
  44. main() {
  45. int ivankaVotes = 0;
  46. int michelleVotes = 0;
  47. int totalVotes = 0;
  48. int state = 0;
  49. int candidateChoice;
  50. int ivankaCount = 0;
  51. int michelleCount = 0;
  52. int statesArray[49];
  53.  
  54. char userChoice = ' ';
  55.  
  56. do {
  57. userChoice = getChoice();
  58. switch(userChoice) {
  59. //Enter Votes for Ivanka Trump >Works
  60. case '1':
  61. printf("You have voted for Ivanka Trump from the state of %d \n", state);
  62. ivankaVotes++;
  63. PAUSE;
  64. break;
  65. //Enter Votes for Michele Obama >Works
  66. case '2':
  67. printf("You have voted for Michele Obama from the state of %d \n", state);
  68. michelleVotes++;
  69. PAUSE;
  70. break;
  71. //Candidate specific view total >Works
  72. case '3':
  73. printf("Please select which candidate you would like to view the votes for! \n");
  74. printf("1. Ivanka Trump \n");
  75. printf("2. Michelle Obama \n");
  76. scanf("%i \n", &candidateChoice);
  77. if (candidateChoice == 2) {
  78. printf("Showing votes for Michelle Obama! \n");
  79. printf("%d \n", michelleVotes);
  80. } else {
  81. printf("Showing votes for Ivanka Trump! \n");
  82. printf("%d \n", ivankaVotes);
  83. };
  84. PAUSE;
  85. break;
  86. //Total Votes for Each Candidate
  87. case '4':
  88. printf("Total votes for Ivanka Trump: %d \n", ivankaVotes);
  89. printf("Total votes for Michelle Obama: %d \n", michelleVotes);
  90. PAUSE;
  91. break;
  92. //All Votes for Each Candidate in order
  93. case '5':
  94. if (ivankaVotes > michelleVotes)
  95. {
  96. printf("Ivanka Trump is current in the lead with %d votes from state %d\n", ivankaVotes, state);
  97. }
  98. else if (michelleVotes > ivankaVotes)
  99. {
  100. printf("Michelle Obama is currently in the lead with %d votes from state %d\n", michelleVotes, state);
  101. }
  102. else(ivankaVotes + michelleVotes >= 0);
  103. {
  104. printf("No Votes have been entered \n");
  105. }
  106. PAUSE;
  107. break;
  108. //Average votes
  109. case '6':
  110. printf(" \n");
  111. //Average Votes
  112. int michelleVotesAverage = (michelleCount / michelleVotes);
  113. int ivankaVotesAverage = (ivankaCount / ivankaVotes);
  114. printf("Michelle Average: %d - Ivanka Average: %d", michelleVotesAverage, ivankaVotesAverage);
  115. //if ()
  116. PAUSE;
  117. break;
  118. //Display Quit Option >Works
  119. case '7':
  120. printf("You have Quit the program! :( \n");
  121. break;
  122. default:
  123. //NO Choice Error Check
  124. printf("You must pick a choice from the menu! \n");
  125. PAUSE;
  126. break;
  127.  
  128. }
  129. } while (userChoice != '6');
  130.  
  131. PAUSE;
  132. }
Add Comment
Please, Sign In to add comment