Advertisement
Guest User

Untitled

a guest
Nov 9th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.52 KB | None | 0 0
  1. /* Program that will simulate a mathematics quiz game
  2. Author: Dylan Heathcote c19434966
  3. Date: 29/10/2019
  4. */
  5.  
  6. #include <stdio.h>
  7. int main()
  8. {
  9. //display menu section
  10. int choice;
  11. int quizTotal = 0;
  12. int correctAnswer = 0;
  13. int incorrectAnswer = 0;
  14. int i;
  15. int quizAttempt = 0;
  16.  
  17.  
  18.  
  19. do
  20. {
  21. printf("\n1). Quiz Duration\n");
  22. printf("2). Start Quiz\n");
  23. printf("3). Display the number of questions that were answered correctly and incorrectly\n");
  24. printf("4). Exit Program\n\n");
  25. scanf(" %d", &choice);
  26. while(getchar()!='\n');
  27.  
  28.  
  29.  
  30. //menu input
  31. switch(choice)
  32. {
  33.  
  34. //menu selection 1
  35. case(1):
  36. { //start case
  37. printf("How many questions would you like to be asked between 1 and 5?\n");
  38.  
  39.  
  40. //check user input for menu selection 1
  41. scanf("%d", &quizTotal);
  42.  
  43. if(quizTotal == 1)
  44. {
  45. printf("\nYou will be asked %d question(s)\n\n", quizTotal);
  46. }
  47.  
  48.  
  49. else if(quizTotal == 2)
  50. {
  51. printf("\nYou will be asked %d question(s)\n\n", quizTotal);
  52. }
  53.  
  54.  
  55. else if(quizTotal == 3)
  56. {
  57. printf("\nYou will be asked %d question(s)\n\n", quizTotal);
  58. }
  59.  
  60.  
  61. else if(quizTotal == 4)
  62. {
  63. printf("\nYou will be asked %d question(s)\n\n", quizTotal);
  64. }
  65.  
  66.  
  67. else if(quizTotal == 5)
  68. {
  69. printf("\nYou will be asked %d question(s)\n\n", quizTotal);
  70. }
  71.  
  72.  
  73. //error check
  74. else
  75. {
  76. do
  77. {
  78. printf("\nPlease enter a valid input \n\n");
  79. scanf("%d", &quizTotal);
  80. }
  81. while(quizTotal >= 6 || quizTotal <= 0);
  82. } //end else
  83.  
  84.  
  85. break;
  86. } //end case 1
  87.  
  88.  
  89.  
  90. //menu selection 2
  91. case(2):
  92. { // start case
  93.  
  94.  
  95. /*
  96. tells the program that the quiz was completed
  97. to satisfy the condition for menu selection 3
  98. */
  99. quizAttempt++;
  100.  
  101.  
  102.  
  103. // user inputs for menu selection 2
  104. printf("You will now be asked %d question(s)\n\n", quizTotal);
  105.  
  106.  
  107. //quiz questions
  108. for(i = 0; i == quizTotal; i++)
  109. {
  110. //local variable
  111. int answer;
  112.  
  113.  
  114.  
  115.  
  116. //question 1
  117. printf("What is 2 + 2?\n");
  118. scanf("%d", &answer);
  119.  
  120. if(answer == 4)
  121. {
  122. printf("Correct!\n\n");
  123. i++;
  124. correctAnswer++;
  125. }
  126.  
  127. else
  128. {
  129. printf("Incorrect! - The answer was: 4\n\n");
  130. i++;
  131. incorrectAnswer++;
  132. }
  133.  
  134.  
  135.  
  136. //question 2
  137. printf("What is 9 * 3?\n");
  138. scanf("%d", &answer);
  139.  
  140. if(answer == 27)
  141. {
  142. printf("Correct!\n\n");
  143. i++;
  144. correctAnswer++;
  145. } //end if question 2
  146.  
  147. else
  148. {
  149. printf("Incorrect! - The answer was: 27\n\n");
  150. i++;
  151. incorrectAnswer++;
  152. } //end else question 2
  153.  
  154.  
  155.  
  156. //question 3
  157. printf("What is 4 / 2?\n");
  158. scanf("%d", &answer);
  159.  
  160. if(answer == 2)
  161. {
  162. printf("Correct!\n\n");
  163. i++;
  164. correctAnswer++;
  165. } //end if question 3
  166.  
  167. else
  168. {
  169. printf("Incorrect! - The answer was: 2\n\n");
  170. i++;
  171. incorrectAnswer++;
  172. } //end else question 3
  173.  
  174.  
  175.  
  176. //question 4
  177. printf("What is 95 - 7?\n");
  178. scanf("%d", &answer);
  179.  
  180. if(answer == 88)
  181. {
  182. printf("Correct!\n\n");
  183. i++;
  184. correctAnswer++;
  185. } //end if question 4
  186.  
  187. else
  188. {
  189. printf("Incorrect! - The answer was: 88\n\n");
  190. i++;
  191. incorrectAnswer++;
  192. } //end else question 4
  193.  
  194.  
  195.  
  196. //question 5
  197. printf("What is 45 * 2?\n");
  198. scanf("%d", &answer);
  199.  
  200. if(answer == 90)
  201. {
  202. printf("Correct!\n\n");
  203. i++;
  204. correctAnswer++;
  205. } //end if question 5
  206.  
  207. else
  208. {
  209. printf("Incorrect! - The answer was: 90\n\n");
  210. i++;
  211. incorrectAnswer++;
  212. } //end else question 5
  213.  
  214. } //end for
  215.  
  216.  
  217. break;
  218. } //end case 2
  219.  
  220.  
  221.  
  222. //menu selection 3
  223. case(3):
  224. {
  225. if(quizAttempt < 1)
  226. {
  227. printf("Sorry you must first complete the test");
  228. }
  229.  
  230. else
  231. {
  232. printf("\nYou have scored %d question(s) correct\n", correctAnswer);
  233. printf("\nYou have scored %d question(s) incorrect\n", incorrectAnswer);
  234. } //end else
  235.  
  236. break;
  237. } //end case 3
  238.  
  239.  
  240. //menu selection 4
  241. case(4):
  242. {
  243. printf("\n\nProgram will now end\n");
  244. printf("Press any key to exit\n");
  245.  
  246. break;
  247. } //end case 4
  248.  
  249.  
  250.  
  251. default:
  252. printf("Invalid input\n\n");
  253. } //end switch
  254.  
  255.  
  256.  
  257. } // end outer do
  258. while(choice != 4);
  259.  
  260.  
  261.  
  262. flushall();
  263. getchar();
  264. return 0;
  265. } //end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement