fork download
  1. //Zachary Abdollahi CS1A Chapter 3, P. 146, #15
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * BEHAVING AS MATH TUTOR
  6.  * _____________________________________________________________________________
  7.  *
  8.  * This program acts as a math tutor for a student. It displays two random
  9.  * numbers to be added, pauses while the student works on the problem, then
  10.  * displays the problem again along with the correct solution when the student
  11.  * is ready.
  12.  *
  13.  * Computation is based on the formula:
  14.  * Sum = Number1 + Number 2
  15.  * _____________________________________________________________________________
  16.  *
  17.  * INPUT
  18.  * number1, number2: Randomly generated numbers to add
  19.  *
  20.  * OUTPUT
  21.  * sum : Sum of number1 and number2
  22.  *
  23.  ******************************************************************************/
  24. #include <iostream>
  25. #include <iomanip>
  26. #include <cstdlib>
  27. #include <ctime>
  28. using namespace std;
  29. int main ()
  30. {
  31. int number1; //INPUT - First random number
  32. int number2; //INPUT - Second random number
  33. int sum; //OUTPUT - Sum of number1 and number2
  34.  
  35. //
  36. // Seed Random Number Generator and Generate Numbers
  37. srand(static_cast<unsigned int>(time(0)));
  38. number1 = rand() % 900 + 100; //Random 3-digit number (100-999)
  39. number2 = rand() % 900 + 100; //Random 3-digit numeber (100-999)
  40.  
  41. //
  42. // Display Problem For Student
  43. cout << " " << number1 << endl;
  44. cout << "+ " << number2 << endl;
  45. cout << "-----" << endl;
  46.  
  47. //
  48. // Pause While Student Works on Problem
  49. cout << endl << "Work on the problem, then press Enter to see the answer...";
  50. cin.get();
  51.  
  52. // Compute Sum
  53. sum = number1 + number2;
  54.  
  55. //
  56. // Output Result
  57. cout << endl << " " << number1 << endl;
  58. cout << "+ " << number2 << endl;
  59. cout << "-----" << endl;
  60. cout << " " << sum << endl;
  61.  
  62. return 0;
  63. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
  864
+ 418
-----

Work on the problem, then press Enter to see the answer...
  864
+ 418
-----
  1282