Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. // Ordered output of three integers
  2. //
  3. // User inputs 3 integers
  4. // The program output these integers ordered
  5.  
  6. #include "std_lib_facilities.h"
  7.  
  8. int main()
  9. {
  10. // promt user to input numbers
  11. cout << "Enter three integers:\n";
  12.  
  13. int init_value{0};
  14. // user input vars
  15. int input1{init_value};
  16. int input2{init_value};
  17. int input3{init_value};
  18. cin >> input1 >> input2 >> input3;
  19.  
  20. // vars for output
  21. int output1{init_value};
  22. int output2{init_value};
  23. int output3{init_value};
  24.  
  25. // when 1st will be printed before 2nd - 3 solutions possible:
  26. //
  27. // (1st 2nd 3rd)
  28. // (1st 3rd 2nd)
  29. // (3rd 1st 2nd)
  30. //
  31.  
  32. if (input1 <= input2) {
  33.  
  34. if (input2 <= input3){
  35. output1 = input1;
  36. output2 = input2;
  37. output3 = input3;
  38. }
  39.  
  40. if (input2 > input3 ){
  41.  
  42. if (input1 <= input3) {
  43. output1 = input1;
  44. output2 = input3;
  45. output3 = input2;
  46. }
  47. if (input1 > input3){
  48. output1 = input3;
  49. output2 = input1;
  50. output3 = input2;
  51. }
  52. }
  53.  
  54. }
  55.  
  56. // when 2nd will be printed before 1st - 3 solutions possible:
  57. //
  58. // (2nd 1st 3rd)
  59. // (3rd 2nd 1st)
  60. // (2nd 3rd 1st)
  61.  
  62. if (input1 > input2) {
  63.  
  64. if (input2 > input3){
  65. output1 = input3;
  66. output2 = input2;
  67. output3 = input1;
  68. }
  69.  
  70. if (input2 <= input3 ){
  71.  
  72. if (input1 <= input3) {
  73. output1 = input2;
  74. output2 = input1;
  75. output3 = input3;
  76. }
  77. if (input1 > input3){
  78. output1 = input2;
  79. output2 = input3;
  80. output3 = input1;
  81. }
  82. }
  83.  
  84. }
  85.  
  86. // output ordered values
  87. cout << output1 << ' ' << output2 << ' ' << output3;
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement