fork download
  1. //Cameron Pham CS1A Chapter 4, P. 220, #1
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * Determine the Minimum or Maximum
  6.  * _____________________________________________________________________________
  7.  *
  8.  * This program accepts two integer values. The program will determine which
  9.  * value is maximum and which value is minimum.
  10.  * _____________________________________________________________________________
  11.  *
  12.  * INPUT
  13.  * Integer value #1
  14.  * Integer value #2
  15.  *
  16.  * OUTPUT
  17.  * Identification of the minimum (minimum number) and maximum (maximum number)
  18.  *
  19.  ******************************************************************************/
  20. #include <iostream>
  21. using namespace std;
  22. int main()
  23. {
  24. float value1; //INPUT - First number entered by the user
  25. float value2; //INPUT - Second number entered by the user
  26. float minimum; //OUTPUT - The minimum of the two numbers
  27. float maximum; //OUTPUT - The maximum of the two numbers
  28.  
  29. // Get input from the user
  30. cout << "Enter the first number: ";
  31. cin >> value1;
  32. cout << endl;
  33. cout << "Enter the second number: ";
  34. cin >> value2;
  35. cout << endl;
  36.  
  37. // Use the conditional operator to determine minimum and maximum
  38. minimum = (value1 < value2) ? value1 : value2;
  39. maximum = (value1 < value2) ? value2 : value1;
  40.  
  41. // Output result
  42. cout << "The minimum number is " << minimum << endl;
  43. cout << "The maximum number is " << maximum << endl;
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 5324KB
stdin
20 48
stdout
Enter the first number: 
Enter the second number: 
The minimum number is 20
The maximum number is 48