Advertisement
Guest User

FinalProjUpdate

a guest
Dec 8th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. int addition();
  5. int main()
  6. {
  7. int i = 50;
  8. int userAns;
  9. int score =0;
  10.  
  11. printf("Hello! Select the game mode you would like to play by choosing the correct corresponding number:"
  12. " \n 1) addition\n 2) subtraction\n2");
  13.  
  14. scanf("%d",&userAns);
  15.  
  16. if(userAns==1)
  17. {
  18. while(i>1)
  19. {
  20. addition();
  21. --i;
  22. printf("\nYou have %d rounds left", i);
  23. }//loop for 50 round
  24. }//close addition branch
  25. if(userAns==2)
  26. {
  27. while(i>1)
  28. {
  29. subtraction();
  30. --i;
  31. printf("\nYou have %d rounds left", i);
  32. }//loop for 50 rounds
  33. }//close subtraction branch
  34. }//end main
  35.  
  36. int addition()
  37. {
  38. int a;
  39. int b;
  40. int ans;
  41.  
  42. a = (rand()%10);
  43. b = (rand()%10);
  44.  
  45. printf("\nWhat is the sum of %d + %d ?", a,b);
  46. scanf("%d",&ans);
  47. if((a+b)==ans)
  48. {
  49. printf("Hooray! That was correct :)");
  50. }
  51. if((a+b)!=ans)
  52. {
  53. printf("Sorry! That was incorrect :(");
  54. }
  55.  
  56. return 0;
  57. }
  58.  
  59. int subtraction()
  60. {
  61. int a;
  62. int b;
  63. int ans;
  64.  
  65. a = (rand()%10);
  66. b = (rand()%10);
  67.  
  68. printf("\nWhat is the sum of %d - %d ?", a,b);
  69. scanf("%d",&ans);
  70. if((a-b)==ans)
  71. {
  72. printf("Hooray! That was correct :)");
  73. }
  74. if((a-b)!=ans)
  75. {
  76. printf("Sorry! That was incorrect :(");
  77. }
  78.  
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement