Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. /*
  2. Author: Anthony Rodriguez, DeAndre Rogers
  3. Date: Nov 6 19
  4. Class: ITSE 1302 - Intro to Computer Programming
  5. Instructor: Prof Welch
  6. The Math Tutor 2
  7. */
  8.  
  9.  
  10. #include <iostream> //cin, cout
  11. #include <iomanip> // setw(), fixed, showpoint, setprecision
  12. #include <string> // get string
  13. #include <cstdlib> // rand()
  14. #include <ctime> // get rand seed
  15. using namespace std;
  16.  
  17. //function prototypes
  18. double addition(double numA,double numB);
  19. double subtraction(double numA,double numB);
  20. double multiplication(double numA,double numB);
  21. double division(double numA,double numB);
  22. int displayMenu();
  23. void add(double numA,double numB,double& numC);
  24. void sub(double numA,double numB,double& numC);
  25. void mult(double numA,double numB, double& numC);
  26. void div(double numA,double numB, double& numC);
  27. int compliment(int compA, int compB, int compC, int compD);
  28. int encourage(int encorA, int encorB, int encorC, int encorD);
  29.  
  30.  
  31.  
  32. int main()
  33. {
  34. int choice;
  35. int numA;
  36. int numB;
  37.  
  38.  
  39.  
  40. do
  41. {
  42. //Seed the random number generator
  43. seed = time(0);
  44.  
  45.  
  46. srand(seed);
  47. num_A = 1 + rand() % 12;
  48. num_B = 1 + rand() % 12;
  49.  
  50. cout << "1. Add\n"
  51. << "2. Subtract\n"
  52. << "3. Multiply\n"
  53. << "4. Divide\n"
  54. << "5. Exit\n";
  55. cin >> choice;
  56.  
  57. if (choice >= 1 && choice <= 5)
  58. {
  59.  
  60. cout << "Enter the total to the following problem:\n";
  61. cout << " " << num_A << endl;
  62.  
  63. switch (choice)
  64. {
  65. case 1: cout << " + ";
  66. total = num_A + num_B;
  67. break;
  68. case 2: total = num_A - num_B;
  69. cout << " - ";
  70. break;
  71. case 3: total = num_A * num_B;
  72. cout << " * ";
  73. break;
  74. case 4: total = num_A / num_B;
  75. cout << " / ";
  76. }
  77.  
  78.  
  79. cout << num_B << endl;
  80. cout << " ------\n ";
  81. cin >> Input;
  82.  
  83. if (Input == total)
  84. cout << "\nGreat Job! " << Input << " is the correct answer.\n\n";
  85. else
  86. {
  87. cout << "\nWrong!\n";
  88. cout << "The correct answer is " << total << endl;
  89. }
  90. }
  91. if (choice < 1 || choice > 5)
  92. {
  93. cout << "Error 404: Please enter the number in range. (Between 1 & 5)\n";
  94. }
  95. if (choice == 5)
  96. cout << "Exiting! See ya around!\n\n";
  97.  
  98. } while (choice != 5);
  99.  
  100. cin.get();
  101. return 0;
  102.  
  103. }
  104.  
  105. //Menu function
  106. /*int displayMenu() {
  107. int choice;
  108.  
  109. cout << "----------------"<< endl;
  110. cout << " Math Tutor Menu \n";
  111. cout << "----------------"<< endl;
  112. cout << "1. Addition" << endl;
  113. cout << "2. Subtraction " << endl;
  114. cout << "3. Multiplication" << endl;
  115. cout << "4. Division " << endl;
  116. cout << "5. Quit the program " <<endl << endl;
  117.  
  118. cin >> choice;
  119.  
  120. cout << endl;
  121. return choice;
  122. }
  123. */
  124. //addition
  125. void add(double numA,double numB,double& numC){
  126. numA = (rand() % (maxNum - minNum + 1)) + minNum;
  127. numB = (rand() % (maxNum - minNum + 1)) + minNum;
  128. numC = numA + numB;
  129.  
  130.  
  131. }
  132.  
  133. double addition(double numA,double numB){
  134.  
  135. double sum = 0;
  136. sum = numA + numB;
  137. return sum;
  138.  
  139. }
  140.  
  141. //subtraction
  142. void sub(double numA,double numB,double& numC){
  143. numA = (rand() % (maxNum - minNum + 1)) + minNum;
  144. numB = (rand() % (maxNum - minNum + 1)) + minNum;
  145. numC = numA - numB;
  146.  
  147. }
  148.  
  149. double subtraction(double numA,double numB){
  150.  
  151. double total = 0;
  152. total = numA - numB;
  153. return total;
  154.  
  155. }
  156. //multiplication
  157. void mult(double numA,double numB, double& numC){
  158. numA = (rand() % (maxNum - minNum + 1)) + minNum;
  159. numB = (rand() % (maxNum - minNum + 1)) + minNum;
  160. numC = numA * numB;
  161.  
  162. }
  163.  
  164. double multiplication(double numA,double numB){
  165.  
  166. double total = 0;
  167. total = numA * numB;
  168. return total;
  169.  
  170. }
  171. //division
  172. void div(double numA,double numB, double& numC){
  173.  
  174. numA = (rand() % (maxNum - minNum + 1)) + minNum;
  175. numB = (rand() % (maxNum - minNum + 1)) + minNum;
  176. numC = numA / numB;
  177.  
  178. }
  179.  
  180. double division(double numA,double numB){
  181.  
  182. double total = 0;
  183. total = numA / numB;
  184. return total;
  185.  
  186. }
  187.  
  188. //int compliment() {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement