fork download
  1. //Ivy Whitney CSC 5 chp. 3, Q# 15
  2.  
  3. /************************************************************
  4. *
  5. * Tutor Student in Addition
  6. *
  7. _____________________________________________________________
  8. * This program displays two random numbers for a young student to
  9. * work on. It then adds the two numbers and displays the correct
  10. * answer
  11. *
  12. * ==================Variables===============================
  13. *
  14. * INPUTs
  15. *
  16. * number1
  17. * number2
  18. *
  19. * OUTPUTs
  20. * sum
  21. *
  22. * ==========================================================
  23. * The MATH...
  24. *
  25. * sum = number1 + number2
  26. **************************************************************/
  27. #include <iostream>
  28. #include <cstdlib>
  29. #include <ctime>
  30. using namespace std;
  31. int main() {
  32. int number1, number2, sum;
  33.  
  34. // random number generator
  35. srand(time(0));
  36.  
  37. // create problem
  38. number1 = rand() % 1000;
  39. number2 = rand() % 1000;
  40.  
  41. // calculate sum
  42. sum = number1 + number2;
  43.  
  44. // display
  45. cout << "Solve the following problem:\n\n";
  46. cout << " " << number1 << endl;
  47. cout << "+ " << number2 << endl;
  48.  
  49. // ask
  50. cout << "\nPress Enter to see the answer.";
  51. cin.get();
  52.  
  53. // answer
  54. cout << "\n " << number1 << endl;
  55. cout << "+ " << number2 << endl;
  56. cout << "-----\n";
  57. cout << " " << sum << endl;
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Solve the following problem:

  426
+ 853

Press Enter to see the answer.
  426
+ 853
-----
  1279