fork download
  1. //Andres Guzman CSC5 Chapter 3, P. 146, #15
  2. //
  3. /**************************************************************
  4. *
  5. * DISPLAY TWO NUMBERS AND REQUIRE INPUT PRIOR TO ANSWER
  6. * ____________________________________________________________
  7. * This program will generate two random numbers and require input to receive answer
  8. * Computation is based on the formula:
  9. * sum = y + x
  10. ____________________________________________________________
  11. * INPUT
  12. * y : generates a random number between 1 and 999
  13. * x : generates a random number between 1 and 999
  14. * OUTPUT
  15. * sum : added total of x and y
  16. **************************************************************/
  17.  
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <cstdlib>
  21. #include <ctime>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. unsigned seed = time(0);
  27. srand(seed);
  28. int y = 1 + rand() % 999;
  29. int x = 1 + rand() % 999;
  30. //
  31. //
  32. cout << right << setw(5) << y << endl;
  33. cout << "+ " << x << endl;
  34. cin.get();
  35. int sum = y + x;
  36. cout << right << setw(6) << "----\n" << right << setw(5) <<sum << endl;
  37. }
Success #stdin #stdout 0.01s 5288KB
stdin
stdout
  844
+ 73
 ----
  917