Advertisement
InasAwad

Untitled

Jun 30th, 2021
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.08 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() % 99 + 10;
  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.  
  114.     void multiplicationAssistLevel1() {
  115.         int answer, product, response;
  116.         int countC = 0, countW = 0;
  117.         int totalPoints = 0;
  118.      
  119.         while (totalPoints < 10) {
  120.             product = multiplicationGenerator1();
  121.             cin >> answer;
  122.  
  123.             while (product != answer) {
  124.                 countW++;
  125.                 response = rand() % 4 + 1;
  126.                 switch (response) {
  127.                 case 1:
  128.                     cout << "No. Please try again." << endl;
  129.                     break;
  130.                 case 2:
  131.                     cout << "Wrong.Try once more." << endl;
  132.                     break;
  133.                 case 3:
  134.                     cout << "Don't give up!" << endl;
  135.                     break;
  136.                 case 4:
  137.                     cout << "No. Keep trying." << endl;
  138.                     break;
  139.                 }
  140.                 if (countW + countC > 9) {
  141.                     break;
  142.                 }
  143.                 else {
  144.  
  145.                     cin >> answer;
  146.                 }
  147.  
  148.             }
  149.  
  150.             if (answer == product) {
  151.                 countC++;
  152.                 response = rand() % 4 + 1;
  153.                 switch (response) {
  154.                 case 1:
  155.                     cout << "Very good!" << endl;
  156.                     break;
  157.                 case 2:
  158.                     cout << "Excellent!" << endl;
  159.                     break;
  160.                 case 3:
  161.                     cout << "Nice work!" << endl;
  162.                     break;
  163.                 case 4:
  164.                     cout << "Keep up the good work!" << endl;
  165.                     break;
  166.                 }
  167.             }
  168.  
  169.             totalPoints = countW + countC;
  170.         }
  171.             cout << "Correct answers " << countC << ", Wrong answers " << countW << endl;
  172.             if (countC >= 8) {
  173.                 cout << "Congratulations, you are ready to go to the next level! " << endl;
  174.                 multiplicationAssistLevel2();
  175.             }
  176.             else if (countW >= 2) {
  177.                 cout << "Please ask your teacher for extra help." << endl;
  178.             }
  179.         }
  180.    
  181.     void additionAssist() {
  182.         int answer, total, response;
  183.         int countC = 0, countW = 0;
  184.         int totalPoints = 0;
  185.  
  186.         while (totalPoints < 10) {
  187.             total = additionGenerator();
  188.             cin >> answer;
  189.  
  190.             while (total != answer) {
  191.                 countW++;
  192.                 response = rand() % 4 + 1;
  193.                 switch (response) {
  194.                 case 1:
  195.                     cout << "No. Please try again." << endl;
  196.                     break;
  197.                 case 2:
  198.                     cout << "Wrong.Try once more." << endl;
  199.                     break;
  200.                 case 3:
  201.                     cout << "Don't give up!" << endl;
  202.                     break;
  203.                 case 4:
  204.                     cout << "No. Keep trying." << endl;
  205.                     break;
  206.                 }
  207.                 if (countW + countC > 9) {
  208.                     break;
  209.                 }
  210.                 else {
  211.  
  212.                     cin >> answer;
  213.                 }
  214.             }
  215.  
  216.             if (answer == total) {
  217.                 countC++;
  218.                 response = rand() % 4 + 1;
  219.                 switch (response) {
  220.                 case 1:
  221.                     cout << "Very good!" << endl;
  222.                     break;
  223.                 case 2:
  224.                     cout << "Excellent!" << endl;
  225.                     break;
  226.                 case 3:
  227.                     cout << "Nice work!" << endl;
  228.                     break;
  229.                 case 4:
  230.                     cout << "Keep up the good work!" << endl;
  231.                     break;
  232.                 }
  233.             }
  234.  
  235.             totalPoints = countW + countC;
  236.         }
  237.         cout << "Correct answers " << countC << ", Wrong answers " << countW << endl;
  238.     }
  239.  
  240.      
  241.     void subractionAssist() {
  242.         unsigned int answer, total, response;
  243.         int countC = 0, countW = 0;
  244.         int totalPoints = 0;
  245.        
  246.         while (totalPoints < 10) {
  247.             total = subractionGenerator();
  248.             cin >> answer;
  249.  
  250.             while (total != answer) {
  251.                 countW++;
  252.                 response = rand() % 4 + 1;
  253.                 switch (response) {
  254.                 case 1:
  255.                     cout << "No. Please try again." << endl;
  256.                     break;
  257.                 case 2:
  258.                     cout << "Wrong.Try once more." << endl;
  259.                     break;
  260.                 case 3:
  261.                     cout << "Don't give up!" << endl;
  262.                     break;
  263.                 case 4:
  264.                     cout << "No. Keep trying." << endl;
  265.                     break;
  266.                 }
  267.                 if (countW + countC > 9) {
  268.                     break;
  269.                 }
  270.                 else {
  271.  
  272.                     cin >> answer;
  273.                 }
  274.             }
  275.  
  276.             if (answer == total) {
  277.                 countC++;
  278.                 response = rand() % 4 + 1;
  279.                 switch (response) {
  280.                 case 1:
  281.                     cout << "Very good!" << endl;
  282.                     break;
  283.                 case 2:
  284.                     cout << "Excellent!" << endl;
  285.                     break;
  286.                 case 3:
  287.                     cout << "Nice work!" << endl;
  288.                     break;
  289.                 case 4:
  290.                     cout << "Keep up the good work!" << endl;
  291.                     break;
  292.                 }
  293.             }
  294.  
  295.             totalPoints = countW + countC;
  296.         }
  297.         cout << "Correct answers " << countC << ", Wrong answers " << countW << endl;
  298.     }
  299.  
  300.     void divisionAssist() {
  301.         unsigned int answer, total, response;
  302.         int countC = 0, countW = 0;
  303.         int totalPoints = 0;
  304.  
  305.         while (totalPoints < 10) {
  306.             total = dvisionGenerator();
  307.             cin >> answer;
  308.  
  309.             while (total != answer) {
  310.                 countW++;
  311.                 response = rand() % 4 + 1;
  312.                 switch (response) {
  313.                 case 1:
  314.                     cout << "No. Please try again." << endl;
  315.                     break;
  316.                 case 2:
  317.                     cout << "Wrong.Try once more." << endl;
  318.                     break;
  319.                 case 3:
  320.                     cout << "Don't give up!" << endl;
  321.                     break;
  322.                 case 4:
  323.                     cout << "No. Keep trying." << endl;
  324.                     break;
  325.                 }
  326.                 if (countW + countC > 9) {
  327.                     break;
  328.                 }
  329.                 else {
  330.  
  331.                     cin >> answer;
  332.                 }
  333.             }
  334.  
  335.             if (answer == total) {
  336.                 countC++;
  337.                 response = rand() % 4 + 1;
  338.                 switch (response) {
  339.                 case 1:
  340.                     cout << "Very good!" << endl;
  341.                     break;
  342.                 case 2:
  343.                     cout << "Excellent!" << endl;
  344.                     break;
  345.                 case 3:
  346.                     cout << "Nice work!" << endl;
  347.                     break;
  348.                 case 4:
  349.                     cout << "Keep up the good work!" << endl;
  350.                     break;
  351.                 }
  352.             }
  353.  
  354.             totalPoints = countW + countC;
  355.         }
  356.         cout << "Correct answers " << countC << ", Wrong answers " << countW << endl;
  357.     }
  358.     int main() {
  359.      
  360.         int choice;
  361.         char x = 'y';
  362.         while (x == 'y') {
  363.             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;
  364.             cin >> choice;
  365.             if (choice == 5) {
  366.                 choice = rand() % 4 + 1;
  367.             }
  368.             switch (choice)
  369.             {
  370.             case 1:
  371.                 cout << "Addition quiz:" << endl;
  372.                 additionAssist();
  373.                 break;
  374.             case 2:
  375.                 cout << "Subtraction quiz:" << endl;
  376.                 subractionAssist();
  377.                 break;
  378.             case 3:
  379.                 cout << "Multiplication quiz: " << endl;
  380.                 multiplicationAssistLevel1();
  381.                 break;
  382.             case 4:
  383.                 cout << "Division quiz" << endl;
  384.                 divisionAssist();
  385.                 break;
  386.             }
  387.             cout << "Enter 'y' for another quiz or 'x' to quit" << endl;
  388.             cin >> x;
  389.  
  390.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement