fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 3 P. 146 #15
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Display Addition Practice
  6.  * ___________________________________________________________________________
  7.  * This program help tutor the user, giving the user time to answer and then
  8.  * displaying the correct answer on the screen
  9.  *
  10.  * The program will use the formual:
  11.  * sum = first number + second number
  12.  * __________________________________________________________________________
  13.  * INPUT
  14.  * num1 //first random number given to user
  15.  * num2 //second random number given to user to add to the first
  16.  *
  17.  * OUTPUT
  18.  * sum //total of number 1 and 2 added together
  19.  ****************************************************************************/
  20. #include <iostream>
  21. #include <cstdlib>
  22. #include <ctime>
  23. #include <limits>
  24. using namespace std;
  25. int main()
  26. {
  27. int num1; //INPUT - first random number given to user
  28. int num2; //INPUT - second random number given to user to add to the first
  29. int sum; //OUTPUT - total of number 1 and 2 added together
  30. //
  31. // Generate two random numbers
  32. srand(static_cast<unsigned int>(time(0)));
  33. num1 = rand() % 900 + 100;
  34. num2 = rand() % 900 + 100;
  35. //
  36. // Display the math problem for the user
  37. cout << "Solve the following additional problem:\n";
  38. cout << " " << num1 << endl;
  39. cout << "+ " << num2 << endl;
  40. //
  41. // Pause and wait for user to press Enter
  42. cout << "\nPress Enter when you're ready to see the answer...";
  43. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  44. //
  45. // Display the answer
  46. sum = num1 + num2;
  47. cout << "\nHere is the correct answer:\n\n";
  48. cout << " " << num1 << endl;
  49. cout << "+ " << num2 << endl;
  50. cout << "------\n";
  51. cout << " " << sum << endl;
  52. return 0;
  53. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Solve the following additional problem:
  185
+ 110

Press Enter when you're ready to see the answer...
Here is the correct answer:

  185
+ 110
------
  295