SHARE
TWEET

Untitled

a guest Jul 17th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ***********************************************************************
  2. //  File:  <mathtutor2.cpp>
  3. //
  4. //        <module name> - <description>
  5. //
  6. //   Author:  <Julia Coleman>
  7. //  Created:  <01/24/2011>
  8. //  Updated:  N/A
  9. //
  10. //  Assignment:  <lab 2>
  11. //    Compiler:  < >
  12. //
  13. // *********************************************************************
  14. //      Inputs: <seed, answer, remainder>
  15. //
  16. //     Outputs: <num1, num2>
  17. //
  18. // Constraints: <>
  19. //
  20. // *********************************************************************
  21. // Design
  22. //   <Int main
  23. //      Int operation, num1, num2, answer, remainder
  24. //      Unsigned seed
  25. //
  26. /**      Get user to input integer
  27.         If number is a valid number say thanks
  28.         If number is not a valid number, end program
  29.     Ask user which operation they would like to perform
  30.         (Addition, Subtraction, Multiplication, and Division)
  31.             If addition, add random numbers
  32.             If subtraction, subtract random numbers
  33.             If multiplication, multiply random numbers
  34.             If division, divide random number
  35.         For all, ask for input and then tell them if it's the right or
  36.         wrong answer. If it is a wrong answer tell them the right one.
  37. */
  38.  
  39. #include <iostream>
  40. #include <cstdlib>
  41. #include <iomanip>
  42. using namespace std;
  43.  
  44. int main()
  45. {
  46.     int operation, num1, num2, answer, remainder,continuity;
  47.     unsigned seed;
  48.  
  49.  
  50.     srand (seed);
  51.     cout <<"Please enter a number that is greater than 0: \n";
  52.     cin >> seed;
  53.     if (seed > 0)
  54.         cout << "Thank you\n\n";
  55.         else
  56.       {
  57.             cout << "That is not a valid input\a";
  58.          return 0;
  59.      }
  60.       num1 = 0 + rand() % 9999;
  61.       num2 = 0 + rand() % 9999;
  62.  
  63.     //ask user which math operation they would like to preform
  64.     cout <<"Math Tutorial Program\n";
  65.     cout <<"1. Addition\n";
  66.     cout <<"2. Subtraction\n";
  67.     cout <<"3. Multiplicatio\n";
  68.     cout <<"4. Division\n";
  69.     cout <<"Press Q to quit\n";
  70.     cout <<"Which math operation would you like to practice?\n";
  71.     cin >> operation ;
  72.                 if (operation > 0)
  73.                     cout << "\n";
  74.                 else
  75.                 {
  76.                 cout << "That is not a valid input";
  77.                     return 0;
  78.                 }
  79.     switch (operation)
  80.     {
  81.         case 1: cout << num1 <<endl;
  82.             cout << "+" <<num2 << endl;
  83.             cout << "_____\n";
  84.             cin >> answer;
  85.                 if (answer > 0)
  86.                     cout << "\n";
  87.                 else
  88.                 {
  89.                 cout << "That is not a valid input";
  90.                     return 0;
  91.                 }
  92.                  if (answer == num1 + num2)
  93.                          cout<<"Good Job! That is correct!\n";
  94.                  else
  95.                          cout<<"Sorry. The answer is: "<< num1 + num2<<endl;
  96.                              break;
  97.         case 2: cout << num1 <<endl;
  98.             cout << "-" <<num2 << endl;
  99.             cout << "_____\n";
  100.             cin >> answer;
  101.                 if (answer > 0 || answer < 0)
  102.                     cout << "\n";
  103.                 else
  104.                 {
  105.                 cout << "That is not a valid input";
  106.                     return 0;
  107.                 }
  108.                     if (answer == num1 - num2)
  109.                          cout<<"Good Job! That is correct!\n";
  110.                     else
  111.                         cout<<"Sorry. The answer is: "<< num1 - num2<<endl;
  112.                             break;
  113.         case 3: cout << num1 <<endl;
  114.             cout << "x" <<num2 << endl;
  115.             cout << "_____\n";
  116.             cin >> answer;
  117.                 if (answer > 0 || answer < 0)
  118.                     cout << "\n";
  119.                 else
  120.                 {
  121.                 cout << "That is not a valid input";
  122.                     return 0;
  123.                 }
  124.                     if (answer == num1*num2)
  125.                         cout <<"Good Job! That is correct!\n";
  126.                     else
  127.                         cout <<"Sorry. The answer is: "<< num1*num2<<endl;
  128.                                 break;
  129.         case 4:
  130.                 cout << "The program will ask you for the whole number and then the remainder.\n";
  131.                         if(num1<num2)
  132.                         num1=num2+23;
  133.                         cout << num1 << "/" <<num2 << "=" <<endl;
  134.                 cin >> answer;
  135.                     if (answer > 0 || answer < 0)
  136.                     cout << "\n";
  137.                     else
  138.                     {
  139.                     cout << "That is not a valid input";
  140.                         return 0;
  141.                     }
  142.             cout << "What is the remainder of " << num1 <<"/"<<num2 <<"? ";
  143.             cin >> remainder;
  144.                     if (answer > 0 || answer < 0)
  145.                     cout << "\n";
  146.                     else
  147.                     {
  148.                     cout << "That is not a valid input";
  149.                         return 0;
  150.                     }
  151.                     if (answer == num1/num2 && remainder == num1%num2)
  152.                         cout << "Good Job! That is correct!\n";
  153.                     else
  154.                         cout << "Sorry the answer is " <<num1/num2 <<" r "<<num1%num2 <<endl;
  155.                                 break;
  156.             case 'Q': cout <<"Thanks!";
  157.                         return 0;
  158.             default: cout << "1,2,3,4 and Q are the only valid choices.";
  159.     }
  160.  
  161.     }
RAW Paste Data
Top