fork download
  1. //Nathanael Schwartz CS1A Chapter 4, P. 220, #1
  2. //
  3. /*******************************************************************************
  4. *
  5. * DETERMINE SMALLER AND LARGER NUMBER
  6. * ______________________________________________________________________________
  7. * This program asks the user two numbers and determines which one is larger and
  8. * smaller.
  9. * ______________________________________________________________________________
  10. * Input
  11. * number1 : the first number entered by the user
  12. * number2 : the second number entered by the user
  13. *
  14. * Output
  15. * largerNumber : the number greater than the other
  16. * smallerNumber : the number less than the other
  17. *
  18. *******************************************************************************/
  19. #include <iostream>
  20. #include <iomanip>
  21. using namespace std;
  22.  
  23. int main() {
  24. float number1; //INPUT - the first number entered
  25. float number2; //INPUT - the second number entered
  26. float largerNumber; //OUTPUT - the larger number
  27. float smallerNumber; //OUTPUT - the smaller number
  28.  
  29. // Ask the user to input the numbers
  30. cin >> number1;
  31. cout << "The first number you entered is: " <<number1 << endl;
  32. cin >> number2;
  33. cout << "The second number you entered is: " <<number2 << endl;
  34.  
  35. // Determine which number is larger and which is smaller
  36. if (number1 > number2)
  37. {
  38. largerNumber = number1;
  39. smallerNumber = number2;
  40. cout << "The larger number is " <<largerNumber << endl;
  41. cout << "The smaller number is " <<smallerNumber << endl;
  42. }
  43. else if (number2 > number1)
  44. {
  45. largerNumber = number2;
  46. smallerNumber = number1;
  47. cout << "The larger number is " <<largerNumber << endl;
  48. cout << "The smaller number is " <<smallerNumber << endl;
  49. }
  50. else
  51. {
  52. cout << "Both numbers are equal to " <<number1 << endl;
  53. }
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5264KB
stdin
12456
123567
stdout
The first number you entered is: 12456
The second number you entered is: 123567
The larger number is 123567
The smaller number is 12456