Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. //Lec12.cpp
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. srand((unsigned int)time(0));
  10.  
  11. cout << "Please enter 1 for multiplication or 2 for division: ";
  12. int math;
  13. cin >> math;
  14.  
  15. while (true) {
  16.  
  17. if (math == 1) {
  18. int randNum1 = 1 + rand() % 9;
  19. int randNum2 = 1 + rand() % 9;
  20.  
  21. int ans = randNum1 * randNum2;
  22.  
  23. while (true) {
  24. cout << "How much is " << randNum1 << " times " << randNum2 << endl;
  25. int StdAns;
  26. cin >> StdAns;
  27.  
  28. if (StdAns == ans) {
  29. cout << "Very good!" << endl;
  30. break;
  31. }
  32. else if (StdAns != ans) {
  33. cout << "No. Please try again" << endl;
  34. }
  35.  
  36. }
  37. }
  38. else if (math == 2) {
  39. int randNum1 = 100 + rand() % 9999;
  40. int randNum2 = 1 + rand() % 99;
  41.  
  42. int ans1 = randNum1 / randNum2;
  43. int ans2 = randNum1 % randNum2;
  44.  
  45. while (true) {
  46. cout << "What is " << randNum1 << " divided by " << randNum2 << endl;
  47. int StdAns1;
  48. cin >> StdAns1;
  49.  
  50. if (StdAns1 == ans1) {
  51. cout << "Very good!" << endl;
  52. break;
  53. }
  54.  
  55. else if (StdAns1 != ans1) {
  56. cout << "No. Please try again" << endl;
  57. }
  58. }
  59.  
  60. while (true) {
  61. cout << "What is the remainder? " << endl;
  62. int StdAns2;
  63. cin >> StdAns2;
  64.  
  65. if (StdAns2 == ans2) {
  66. cout << "Very good!" << endl;
  67. break;
  68. }
  69.  
  70. else if (StdAns2 != ans2) {
  71. cout << "No. Please try again" << endl;
  72. }
  73. }
  74.  
  75. }
  76.  
  77. }
  78.  
  79. system("pause");
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement