fork download
  1. //Diego Martinez CSC5 Chapter 3, P. 146,#15
  2.  
  3. /*******************************************************************************
  4. * Studying with a Math Tutor
  5. * ______________________________________________________________________________
  6. * This program is designed as a simple math tutor for young students to practice
  7. * addition.
  8. *
  9. * Computation is based on the Formula:
  10. * num1 = the first random number
  11. * num2 = the second random number
  12. * sum = the result of adding num1 and num2
  13. *_______________________________________________________________________________
  14. * INPUT
  15. * User Inputs
  16. *
  17. * OUTPUT
  18. * Addition problem display
  19. * Correct answer display
  20. *******************************************************************************/
  21. #include <iostream>
  22. #include <cstdlib>
  23. #include <ctime>
  24.  
  25. using namespace std;
  26.  
  27. int main() {
  28. int num1, num2, sum;
  29.  
  30. // Seed the random number generator
  31. srand(time(0));
  32.  
  33. // Generate two random numbers (0–999)
  34. num1 = rand() % 1000;
  35. num2 = rand() % 1000;
  36.  
  37. // Calculate the sum
  38. sum = num1 + num2;
  39.  
  40. // Display the problem
  41. cout << "Solve the following problem:\n\n";
  42. cout << " " << num1 << endl;
  43. cout << "+ " << num2 << endl;
  44.  
  45. // Pause until the student is ready
  46. cout << "\nPress Enter to see the answer...";
  47. cin.get();
  48.  
  49. // Display the correct answer
  50. cout << "\n " << num1 << endl;
  51. cout << "+ " << num2 << endl;
  52. cout << "-----\n";
  53. cout << " " << sum << endl;
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Solve the following problem:

  932
+ 358

Press Enter to see the answer...
  932
+ 358
-----
  1290