Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int num1,
  10. num2,
  11. choice,
  12. studentAnswer,
  13. correctAnswer;
  14.  
  15. srand(time(0));
  16. do
  17. {
  18. cout << "n-----------------------------------n"
  19. << " Math Tutorn"
  20. << " M E N Un"
  21. << "-----------------------------------n";
  22. cout << "1. Addition problemn";
  23. cout << "2. Subtraction problemn";
  24. cout << "3. Multiplication problemn";
  25. cout << "4. Division problemn";
  26. cout << "5. Quit this programn";
  27. cout << "------------------------------n";
  28. cout << "Enter your choice (1-5): ";
  29. cin >> choice;
  30. while (choice < 1 || choice > 5)
  31. {
  32. cout << "The valid choices are 1, 2, 3, "
  33. << "4, and 5. Please choose: ";
  34. cin >> choice;
  35. }
  36. switch (choice)
  37. {
  38. case 1:
  39. num1 = 1 + rand() % 500;
  40. num2 = 1 + rand() % 500;
  41. correctAnswer = num1 + num2;
  42. cout << "nn";
  43. cout << " " << setw(4) << num1 << endl;
  44. cout << " +" << setw(4) << num2 << endl;
  45. cout << " " << "----" << endl;
  46. cout << " ";
  47. break;
  48. case 2:
  49. num1 = 1 + rand() % 999;
  50. num2 = 1 + rand() % 999;
  51. while (num2 > num1)
  52. num2 = 1 + rand() % 999;
  53. correctAnswer = num1 - num2;
  54. cout << "nn";
  55. cout << " " << setw(4) << num1 << endl;
  56. cout << " -" << setw(4) << num2 << endl;
  57. cout << " " << "----" << endl;
  58. cout << " ";
  59. break;
  60. case 3:
  61. num1 = 1 + rand() % 100;
  62. num2 = 1 + rand() % 9;
  63. correctAnswer = num1 * num2;
  64. cout << "nn";
  65. cout << " " << setw(4) << num1 << endl;
  66. cout << " *" << setw(4) << num2 << endl;
  67. cout << " " << "----" << endl;
  68. cout << " ";
  69. break;
  70. case 4:
  71. num2 = 1 + rand() % 9;
  72. num1 = num2 * (rand() % 50 + 1);
  73. correctAnswer = num1 / num2;
  74. cout << "nn";
  75. cout << " " << num1 << " / " << num2 << " = ";
  76. break;
  77. case 5:
  78. cout << "Thank you for using Math Tutor.nn";
  79. break;
  80. }
  81. if (choice >= 1 && choice <= 4)
  82. {
  83. cin >> studentAnswer;
  84. if (studentAnswer == correctAnswer)
  85. cout << "nnCongratulations! That's right.nn";
  86. else
  87. cout << "nnSorry, the correct answer is " << correctAnswer
  88. << ".nn";
  89. }
  90. } while (choice != 5);
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement