Advertisement
InasAwad

Untitled

Jun 30th, 2021
911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.11 KB | None | 0 0
  1.     unsigned int dvisionGenerator() {
  2.         int num1, num2;
  3.         srand(static_cast<int>(time(0)));
  4.         num1 = rand() % 19 + 1;
  5.         num2 = rand() % 9 + 1;
  6.         while (num1% num2 != 0) {
  7.             num1 = rand() % 9 + 1;
  8.         }
  9.         cout << "How much is " << num1 << " divided by " << num2 << "?" << endl;
  10.         return num1 / num2;
  11.     }
  12.  
  13.    unsigned int subractionGenerator() {
  14.         int num1, num2;
  15.         srand(static_cast<int>(time(0)));
  16.         num1 = rand() % 9 + 1;
  17.         num2 = rand() % 9 + 1;
  18.         while (num1 < num2) {
  19.             num1 = rand() % 9 + 1;
  20.         }
  21.         cout << "How much is " << num1 << " mius " << num2 << " ?" << endl;
  22.         return num1 - num2;
  23.     }
  24.     int additionGenerator() {
  25.         int num1, num2;
  26.         srand(static_cast<int>(time(0)));
  27.         num1 = rand() % 9 + 1;
  28.         num2 = rand() % 9 + 1;
  29.         cout << "How much is " << num1 << " plus " << num2 << " ?" << endl;
  30.         return num1 + num2;
  31.     }
  32.     int multiplicationGenerator1() {
  33.         int num1, num2;
  34.         srand(static_cast<int>(time(0)));
  35.         num1 = rand() % 9 + 1;
  36.         num2 = rand() % 9 + 1;
  37.         cout << "How much is " << num1 << " times " << num2 << " ?" << endl;
  38.         return num1 * num2;
  39.     }
  40.     int multiplicationGenerator2() {
  41.         int num1, num2;
  42.         srand(static_cast<int>(time(0)));
  43.         num1 = rand() % 19 + 1;
  44.         num2 = rand() % 9 + 1;
  45.         cout << "How much is " << num1 << " times " << num2 << " ?" << endl;
  46.         return num1 * num2;
  47.     }
  48.  
  49.     void multiplicationAssistLevel2() {
  50.         int answer, product, response;
  51.         int countC = 0, countW = 0;
  52.         int totalPoints = 0;
  53.  
  54.         while (totalPoints < 10) {
  55.             product = multiplicationGenerator2();
  56.             cin >> answer;
  57.  
  58.             while (product != answer) {
  59.                 countW++;
  60.                 response = rand() % 4 + 1;
  61.                 switch (response) {
  62.                 case 1:
  63.                     cout << "No. Please try again." << endl;
  64.                     break;
  65.                 case 2:
  66.                     cout << "Wrong.Try once more." << endl;
  67.                     break;
  68.                 case 3:
  69.                     cout << "Don't give up!" << endl;
  70.                     break;
  71.                 case 4:
  72.                     cout << "No. Keep trying." << endl;
  73.                     break;
  74.                 }
  75.  
  76.                 if (countW + countC > 9) {
  77.                     break;
  78.                 }
  79.                 else {
  80.                     cin >> answer;
  81.                 }
  82.             }
  83.  
  84.             if (answer == product) {
  85.                 countC++;
  86.                 response = rand() % 4 + 1;
  87.                 switch (response) {
  88.                 case 1:
  89.                     cout << "Very good!" << endl;
  90.                     break;
  91.                 case 2:
  92.                     cout << "Excellent!" << endl;
  93.                     break;
  94.                 case 3:
  95.                     cout << "Nice work!" << endl;
  96.                     break;
  97.                 case 4:
  98.                     cout << "Keep up the good work!" << endl;
  99.                     break;
  100.                 }
  101.             }
  102.  
  103.             totalPoints = countW + countC;
  104.         }
  105.         cout << "Correct answers " << countC << " Wrong answers " << countW << endl;
  106.         if (countC >= 8) {
  107.             cout << "Congratulations, you are ready to go to the next level! " << endl;
  108.         }
  109.         else if (countW >= 2) {
  110.             cout << "Please ask your teacher for extra help." << endl;
  111.         }
  112.     }
  113.     void wrongAnswer() {
  114.         int response;
  115.         response = rand() % 4 + 1;
  116.         switch (response) {
  117.         case 1:
  118.             cout << "No. Please try again." << endl;
  119.             break;
  120.         case 2:
  121.             cout << "Wrong.Try once more." << endl;
  122.             break;
  123.         case 3:
  124.             cout << "Don't give up!" << endl;
  125.             break;
  126.         case 4:
  127.             cout << "No. Keep trying." << endl;
  128.             break;
  129.         }
  130.     }
  131.     void correctAnswer() {
  132.         int response;
  133.         response = rand() % 4 + 1;
  134.         switch (response) {
  135.         case 1:
  136.             cout << "Very good!" << endl;
  137.             break;
  138.         case 2:
  139.             cout << "Excellent!" << endl;
  140.             break;
  141.         case 3:
  142.             cout << "Nice work!" << endl;
  143.             break;
  144.         case 4:
  145.             cout << "Keep up the good work!" << endl;
  146.             break;
  147.         }
  148.     }
  149.     void multiplicationAssistLevel1() {
  150.         int answer, product;
  151.         int countC = 0, countW = 0;
  152.         int totalPoints = 0;
  153.      
  154.         while (totalPoints < 10) {
  155.             product = multiplicationGenerator1();
  156.             cin >> answer;
  157.  
  158.             while (product != answer) {
  159.                 countW++;
  160.                 wrongAnswer();
  161.                 if (countW + countC > 9) {
  162.                     break;
  163.                 }
  164.                 else
  165.                 {
  166.                     cin >> answer;
  167.                 }
  168.             }
  169.  
  170.             if (answer == product) {
  171.                 countC++;
  172.                 correctAnswer();
  173.             }
  174.  
  175.             totalPoints = countW + countC;
  176.         }
  177.             cout << "Correct answers " << countC << ", Wrong answers " << countW << endl;
  178.             if (countC >= 8) {
  179.                 cout << "Congratulations, you are ready to go to the next level! " << endl;
  180.                 multiplicationAssistLevel2();
  181.             }
  182.             else if (countW >= 2) {
  183.                 cout << "Please ask your teacher for extra help." << endl;
  184.             }
  185.         }
  186.    
  187.     void additionAssist() {
  188.         int answer, total;
  189.         int countC = 0, countW = 0;
  190.         int totalPoints = 0;
  191.  
  192.         while (totalPoints < 10) {
  193.             total = additionGenerator();
  194.             cin >> answer;
  195.  
  196.             while (total != answer) {
  197.                 countW++;
  198.                 wrongAnswer();
  199.                 if (countW + countC > 9) {
  200.                     break;
  201.                 }
  202.                 else
  203.                 {
  204.                     cin >> answer;
  205.                 }
  206.             }
  207.  
  208.             if (answer == total) {
  209.                 countC++;
  210.                 correctAnswer();
  211.             }
  212.  
  213.             totalPoints = countW + countC;
  214.         }
  215.         cout << "Correct answers " << countC << ", Wrong answers " << countW << endl;
  216.     }
  217.  
  218.      
  219.     void subractionAssist() {
  220.         unsigned int answer, total;
  221.         int countC = 0, countW = 0;
  222.         int totalPoints = 0;
  223.        
  224.         while (totalPoints < 10) {
  225.             total = subractionGenerator();
  226.             cin >> answer;
  227.  
  228.             while (total != answer) {
  229.                 countW++;
  230.                 wrongAnswer();
  231.                 if (countW + countC > 9)
  232.                 {
  233.                     break;
  234.                 }
  235.                 else
  236.                 {
  237.                  cin >> answer;
  238.                 }
  239.             }
  240.             if (answer == total)
  241.             {
  242.                 countC++;
  243.                 correctAnswer();
  244.             }
  245.             totalPoints = countW + countC;
  246.         }
  247.         cout << "Correct answers " << countC << ", Wrong answers " << countW << endl;
  248.     }
  249.  
  250.     void divisionAssist() {
  251.         unsigned int answer, total;
  252.         int countC = 0, countW = 0;
  253.         int totalPoints = 0;
  254.  
  255.         while (totalPoints < 10) {
  256.             total = dvisionGenerator();
  257.             cin >> answer;
  258.  
  259.             while (total != answer) {
  260.                 countW++;
  261.                 wrongAnswer();
  262.                 if (countW + countC > 9) {
  263.                     break;
  264.                 }
  265.                 else
  266.                 {
  267.                     cin >> answer;
  268.                 }
  269.             }
  270.             if (answer == total) {
  271.                 countC++;
  272.                 correctAnswer();
  273.             }
  274.             totalPoints = countW + countC;
  275.         }
  276.         cout << "Correct answers " << countC << ", Wrong answers " << countW << endl;
  277.     }
  278.     int main() {
  279.      
  280.         int choice;
  281.         char x = 'y';
  282.         while (x == 'y') {
  283.             cout << "Please enter a choice: \n'1' for addition  \n'2' for subraction \n'3' for multiplication \n'4' for division \n'5' for a random choice  " << endl;
  284.             cin >> choice;
  285.             if (choice == 5) {
  286.                 choice = rand() % 4 + 1;
  287.             }
  288.             switch (choice)
  289.             {
  290.             case 1:
  291.                 cout << "Addition quiz:" << endl;
  292.                 additionAssist();
  293.                 break;
  294.             case 2:
  295.                 cout << "Subtraction quiz:" << endl;
  296.                 subractionAssist();
  297.                 break;
  298.             case 3:
  299.                 cout << "Multiplication quiz: " << endl;
  300.                 multiplicationAssistLevel1();
  301.                 break;
  302.             case 4:
  303.                 cout << "Division quiz" << endl;
  304.                 divisionAssist();
  305.                 break;
  306.             }
  307.             cout << "Enter 'y' for another quiz or 'x' to quit" << endl;
  308.             cin >> x;
  309.         }
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement