fork download
  1. // Elaine Torrez Chapter 4 P. 220, #1
  2. /**************************************************************************
  3.  * MINIMUM / MAXIMUM
  4.  * ------------------------------------------------------------------------
  5.  * This program asks the user to enter two numbers. It then uses the
  6.  * conditional operator (?:) to determine which number is smaller and
  7.  * which number is larger, and displays the results.
  8.  * ------------------------------------------------------------------------
  9.  * INPUT
  10.  * num1 : First number
  11.  * num2 : Second number
  12.  *
  13.  * OUTPUT
  14.  * The smaller number
  15.  * The larger number
  16.  **************************************************************************/
  17.  
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. int main()
  22. {
  23. int num1, num2; // User input numbers
  24. int smaller, larger;
  25.  
  26. // Get input
  27. cout << "Enter the first number: ";
  28. cin >> num1;
  29. cout << "Enter the second number: ";
  30. cin >> num2;
  31.  
  32. // Conditional operator (?:) to determine smaller/larger
  33. smaller = (num1 < num2) ? num1 : num2;
  34. larger = (num1 > num2) ? num1 : num2;
  35.  
  36. // Display results
  37. cout << "The smaller number is: " << smaller << endl;
  38. cout << "The larger number is: " << larger << endl;
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Enter the first number: Enter the second number: The smaller number is: 22042
The larger number is: 771224272