fork download
  1. // Cenyao Huang CS1A Homework 4, p. 220, #1
  2.  
  3. /*********************************************************************************************
  4. * DETERMINE THE GREATER NUMBER
  5. *
  6. * This program determines which of two entered numbers is greater.
  7. *
  8. * Input
  9. * num1 : the value of the first entered number
  10. * num2 : the value of the second entered number
  11. *
  12. * Output
  13. * A message that displays the greater number, or to try again if the input
  14. * numbers are equal or not a number
  15. *
  16. *******************************************************************************************/
  17.  
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. int main() {
  22. double num1, num2; // assign variables
  23.  
  24. // data is asked for, entered, and displayed
  25. cout << "Please enter two different numbers and we will determine which is greater: ";
  26. cin >> num1 >> num2;
  27. cout << num1 << " " << num2 << endl;
  28.  
  29. // determine the greater number
  30. if (num1 > num2)
  31. cout << "The greater number is: " << num1;
  32. else if (num2 > num1)
  33. cout << "The greater number is: " << num2;
  34. else
  35. cout << "Invalid numbers. Please try again. ";
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5272KB
stdin
2 2
stdout
Please enter two different numbers and we will determine which is greater: 2 2
Invalid numbers. Please try again.