Advertisement
Guest User

Code

a guest
Jun 2nd, 2014
1,438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5.  
  6. int input();
  7. int addition(int number1, int number2);
  8. int multiplication(int number1, int number2);
  9.  
  10.  
  11. int main()
  12.  
  13. {
  14. time_t t;
  15. int number1, number2, answer, userAnswer;
  16. int score = 0;
  17. int prevScore = 0;
  18. int i = 0;
  19. char optionTwo = 'E';
  20. char option;
  21. int none[5];
  22. int ntwo[5];
  23.  
  24.  
  25. srand((unsigned)time(&t));
  26.  
  27. while(optionTwo == 'E')
  28. {
  29. option = input();
  30.  
  31. switch(option)
  32. {
  33. case 'A': for(i=0;i<5;i++)
  34. {
  35. number1 = rand()%10;
  36. number2 = rand()%10;
  37. answer = addition(number1,number2);
  38. printf("\n\nYour current score is: %d of %d\n", score, i);
  39. printf("What is %d + %d?\n", number1, number2);
  40. printf("Your answer:");
  41. scanf("%d", &userAnswer);
  42.  
  43. if (answer == userAnswer)
  44. {
  45. printf("Correct!\n");
  46. score = prevScore + 1;
  47. prevScore = score;
  48. }
  49.  
  50. else
  51. {
  52. printf("Incorrect. The correct answer was %d\n\n", answer);
  53. none[i] = number1;
  54. ntwo[i] = number2;
  55. }
  56. }
  57. break;
  58.  
  59. case 'M': for(i=0;i<5;i++)
  60. {
  61. number1 = rand()%10;
  62. number2 = rand()%10;
  63. answer = multiplication(number1,number2);
  64. printf("\n\nYour current score is: %d\n", score);
  65. printf("What is %d x %d?\n", number1, number2);
  66. printf("Your answer:");
  67. scanf("%d", &userAnswer);
  68.  
  69. if (answer == userAnswer)
  70. {
  71. printf("Correct!\n");
  72. score = prevScore + 1;
  73. prevScore = score;
  74. }
  75.  
  76. else
  77. {
  78. printf("Incorrect. The correct answer was %d\n\n", answer);
  79. none[i] = number1;
  80. ntwo[i] = number2;
  81. }
  82. }
  83. break;
  84.  
  85. case 'Q': printf("Thank your for playing.");
  86. return(0);
  87.  
  88.  
  89. default: printf("You entered an invalid option. The program will now terminate.\n");
  90. return (0);
  91. }
  92.  
  93. printf("\n\nYour total score is: %d of %d. You got the following questions wrong.\n", score, i);
  94.  
  95. for(i=0;i<5;i++)
  96. {
  97. printf("Question [i]: none[i]+ntwo[i]");
  98. }
  99.  
  100.  
  101. printf("Press (E) to exit this session.");
  102. printf("Your choice:");
  103. scanf(" %c", &optionTwo);
  104. }
  105.  
  106.  
  107. return 0;
  108. }
  109.  
  110. int input()
  111. {
  112. char option;
  113. printf("\n\n**************************************************************************************************************\n");
  114. printf("* ~~ Math Flash Card Game ~~ *\n");
  115. printf("* *\n");
  116. printf("* Please choose what type of game mode you would like to eneter. *\n");
  117. printf("* *\n");
  118. printf("* (A) Addition *\n");
  119. printf("* (M) Multiplication *\n");
  120. printf("* (Q) Quit *\n");
  121. printf("* *\n");
  122. printf("**************************************************************************************************************\n");
  123.  
  124. printf("Your option:");
  125. scanf("%c", &option);
  126.  
  127. return option;
  128. }
  129.  
  130. int addition(int number1, int number2)
  131. {
  132. int answer;
  133. answer = number1 + number2;
  134. return answer;
  135. }
  136.  
  137. int multiplication(int number1, int number2)
  138. {
  139. int answer;
  140. answer = number1 * number2;
  141. return answer;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement