fork download
  1. //Jacklyn Isordia CSC5 Chapter 3, P. 146, #15
  2. //
  3. /**************************************************************
  4.  *
  5.  * Math Tutor
  6.  * ____________________________________________________________
  7.  * This program displays two random numbers that a student must
  8.  * add together. The program pauses until the student presses
  9.  * a key, then displays the correct answer.
  10.  * ____________________________________________________________
  11.  * INPUT
  12.  * (none)
  13.  *
  14.  * OUTPUT
  15.  * num1, num2 : two random numbers to add
  16.  * sum : correct answer
  17.  *
  18.  **************************************************************/
  19. #include <iostream>
  20. #include <cstdlib>
  21. #include <ctime>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. int num1;
  27. int num2;
  28. int sum;
  29.  
  30. //
  31. // Generate Random Numbers
  32. //
  33. srand(time(0));
  34.  
  35. num1 = rand() % 900 + 100; // random 3-digit number
  36. num2 = rand() % 900 + 100; // random 3-digit number
  37.  
  38. //
  39. // Compute Sum
  40. //
  41. sum = num1 + num2;
  42.  
  43. //
  44. // Display Answer
  45. //
  46.  
  47. cout << endl;
  48. cout << " " << num1 << endl;
  49. cout << "+ " << num2 << endl;
  50. cout << "----" << endl;
  51. cout << " " << sum << endl;
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
  824
+ 859
----
  1683