Advertisement
HakdogForce

Sorting 5 numbers ( still error num5 need to fix ASAP)

Sep 2nd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // road to Unoooooooooooooooooooooooooooooooo!
  5.  
  6. int main (){
  7. int num1, num2, num3, num4, num5;
  8. int temp1, temp2, temp3, temp4, temp5;
  9.  
  10. cout << "sort the numbers into their descending order. " << endl << endl;
  11.  
  12. // prompt user to enter 5 random integers
  13. cout << "Enter the 5 integers that you wish to sort: " << endl;
  14.  
  15. cin >> num1 >> num2 >> num3 >> num4 >> num5;
  16.  
  17. int firstNum, secondNum, thirdNum, fourthNum, fifthNum; // declare the firstNum, secondNum, thirdNum, fourthNum, fifthNum
  18.  
  19. // Start of firstNumber
  20. if (num1 > num2 && num1 > num3 && num1 > num4 && num1 > num5){
  21. firstNum = num1;
  22. } else if (num2 > num1 && num2 > num3 && num2 > num4 && num2 > num5){
  23. secondNum = num2;
  24. } else if (num3 > num1 && num3 > num2 && num3 > num4 && num3 > num5){
  25. thirdNum = num3;
  26. } else if (num4 > num1 && num4 > num2 && num4 > num3 && num4 > num5){
  27. fourthNum = num4;
  28. } else if (num5 > num1 && num5 > num2 && num5 > num3 && num5 > num4){
  29. fifthNum = num5;
  30. }
  31. // end of firstNumber
  32.  
  33. // start of fourthNumber
  34.  
  35. if (num1 < num2 && num1 < num3 && num1 < num4 && num1 < num5){
  36. fourthNum = num1;
  37. }
  38. else if (num2 < num1 && num2 < num3 && num2 < num4 && num2 < num5){
  39. fourthNum = num2;
  40. }
  41. else if (num3 < num1 && num3 < num2 && num3 < num4 && num3 < num5){
  42. fourthNum = num3;
  43. }
  44. else if (num4 < num1 && num4 < num2 && num4 < num3 && num4 < num5){
  45. fourthNum = num4;
  46. }
  47. else if (num5 < num1 && num5 < num2 && num5 < num3 && num5 < num4){
  48. fourthNum = num5;
  49. }
  50. // end of fourthNumber
  51.  
  52. // start of secondNumber
  53. if (num1 != firstNum && num1 != fourthNum && num1 != fifthNum){
  54. temp1 = num1;
  55. }
  56. if (num2 != firstNum && num2 != fourthNum && num1 != fifthNum){
  57. temp2 = num2;
  58. }
  59. if (num3 != firstNum && num3 != fourthNum && num1 != fifthNum){
  60. temp3 = num3;
  61. }
  62. if (num4 != firstNum && num4 != fourthNum && num1 != fifthNum){
  63. temp4 = num4;
  64. }
  65. if (num5 != firstNum && num5 != fourthNum && num1 != fifthNum){
  66. temp5 = num5;
  67. }
  68.  
  69. if (temp1 > temp2 && temp1 > temp3 && temp1 > temp4 && temp1 > temp5){
  70. secondNum = num1;
  71. } else if (temp2 > temp1 && temp2 > temp3 && temp2 > temp4 && temp2 > temp5){
  72. secondNum = num2;
  73. } else if (temp3 > temp1 && temp3 > temp2 && temp3 > temp4 && temp3 > temp5){
  74. secondNum = num3;
  75. } else if (temp4 > temp1 && temp4 > temp2 && temp4 > temp3 && temp4 > temp5){
  76. secondNum = num4;
  77. } else if (temp5 > temp1 && temp5 > temp2 && temp5 > temp3 && temp5 > temp4){
  78. secondNum = num5;
  79. }
  80. // end of SecondNumber
  81.  
  82. // Start of thirdNumber
  83. if (num1 != firstNum && num1 != secondNum && num1 != fourthNum && num1 != fifthNum ){
  84. thirdNum = num1;
  85. }
  86. else if (num2 != firstNum && num2 != secondNum && num2 != fourthNum && num2 != fifthNum){
  87. thirdNum = num2;
  88. }
  89. else if (num3 != firstNum && num3 != secondNum && num3 != fourthNum && num3 != fifthNum){
  90. thirdNum = num3;
  91. }
  92. else if (num4 != firstNum && num4 != secondNum && num4 != fourthNum && num4 != fifthNum){
  93. thirdNum = num4;
  94. }
  95. else if (num5 != firstNum && num5 != secondNum && num5 != fourthNum && num5 != fifthNum){
  96. thirdNum = num5;
  97. }
  98. // end of thirdNumber
  99.  
  100. // start of fifthNum
  101.  
  102. if (num1 != firstNum && num1 != secondNum && num1 != thirdNum && num1 != fourthNum){
  103. fifthNum = num1;
  104. }
  105. else if (num2 != firstNum && num2 != secondNum && num2 != thirdNum && num2 != fourthNum){
  106. fifthNum = num2;
  107. }
  108. else if (num3 != firstNum && num3 != secondNum && num3 != thirdNum && num3 != fourthNum){
  109. fifthNum = num3;
  110. }
  111. else if (num4 != firstNum && num4 != secondNum && num4 != thirdNum && num4 != fourthNum){
  112. fifthNum = num4;
  113. }
  114. else if (num5 != firstNum && num5 != secondNum && num5 != thirdNum && num5 != fourthNum){
  115. fifthNum = num5;
  116. }
  117.  
  118. cout << "\n" << "The ascending order for the 5 numbers you just entered are: " << endl;
  119. cout << firstNum << " " << secondNum << " " << thirdNum << " " << fourthNum << " " << fifthNum << endl;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement