fork download
  1. //OrinTill Qimid CS1A Chapter 3, P. 146, #15
  2. //
  3. /**************************************************************
  4.  * Addition of random number
  5.  *
  6.  * ____________________________________________________________
  7.  * This program generates two random numbers, displays them in an addition format, and waits for the user to press the Enter key before showing the result of the addition.
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * enter: any that the user press.
  11.  *
  12.  * OUTPUT
  13.  * number1 : random number1
  14.  * number2 : random number2
  15.  * total : total of the 2 random number
  16.  *
  17.  **************************************************************/
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <cmath>
  21. #include <cstdlib>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. float number1,
  27. number2,
  28. total;
  29. number1 = rand();
  30. number2 = rand();
  31. cout <<" " << number1 << endl; // Display the numbers
  32. cout <<"+" << " _____"<< endl;
  33. cout <<" "<< number2 << endl;
  34. cout<<"press any key to see the answer."<< endl; // Wait for the user to press Enter
  35. cin.get();
  36. total = number1 + number2; // Calculate the total
  37. cout <<" " << number1 << endl; // Display the result
  38. cout <<" "<< number2 << endl;
  39. cout <<"+" << " _____"<< endl;
  40. cout <<" " << total<< endl;
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty