fork download
  1. //Maxwell Brewer CS1A Chapter 4, P. 220, #1
  2. //
  3. /***************************************************************
  4.  *
  5.  * OUTPUT MINIMUM MAXIMUM
  6.  * _____________________________________________________________
  7.  *
  8.  * This program will use the if then else
  9.  * statement to determine the larger of
  10.  * two numbers.
  11.  * _____________________________________________
  12.  * INPUT
  13.  *
  14.  * a, b
  15.  *
  16.  * OUTPUT
  17.  *
  18.  * a, b
  19.  *
  20.  ***************************************************************/
  21.  
  22. #include <iostream>
  23. #include <iomanip>
  24. #include <cmath>
  25. #include <string>
  26.  
  27. using namespace std;
  28.  
  29. int main() {
  30.  
  31. // Initialization
  32.  
  33. const char MSG_1[] = "Enter the 1st number: \n";
  34. const char MSG_2[] = "Enter the 2nd number: \n";
  35.  
  36. const char MSG_3[] = "The larger number is: \n";
  37. const char MSG_4[] = "The smaller number is: \n";
  38. const char MSG_5[] = "Both numbers are equal.";
  39.  
  40. int a;
  41. int b;
  42.  
  43. // Display input prompts
  44.  
  45. cout << MSG_1;
  46. cin >> a;
  47. cout << MSG_2;
  48. cin >> b;
  49.  
  50. // Output
  51.  
  52. if (a > b)
  53. {
  54. cout << MSG_3 << a << endl;
  55. cout << MSG_4 << b << endl;
  56. }
  57.  
  58. else if (b > a)
  59. {
  60. cout << MSG_3 << b << endl;
  61. cout << MSG_4 << a << endl;
  62. }
  63.  
  64. else
  65. {
  66. cout << MSG_5 << endl;
  67. }
  68.  
  69.  
  70.  
  71. return 0;
  72. }
Success #stdin #stdout 0.01s 5268KB
stdin
10
10
stdout
Enter the 1st number: 
Enter the 2nd number: 
Both numbers are equal.