Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // road to Unoooooooooooooooooooooooooooooooo!
- int main (){
- int num1, num2, num3, num4, num5;
- int temp1, temp2, temp3, temp4, temp5;
- cout << "sort the numbers into their descending order. " << endl << endl;
- // prompt user to enter 5 random integers
- cout << "Enter the 5 integers that you wish to sort: " << endl;
- cin >> num1 >> num2 >> num3 >> num4 >> num5;
- int firstNum, secondNum, thirdNum, fourthNum, fifthNum; // declare the firstNum, secondNum, thirdNum, fourthNum, fifthNum
- // Start of firstNumber
- if (num1 > num2 && num1 > num3 && num1 > num4 && num1 > num5){
- firstNum = num1;
- } else if (num2 > num1 && num2 > num3 && num2 > num4 && num2 > num5){
- secondNum = num2;
- } else if (num3 > num1 && num3 > num2 && num3 > num4 && num3 > num5){
- thirdNum = num3;
- } else if (num4 > num1 && num4 > num2 && num4 > num3 && num4 > num5){
- fourthNum = num4;
- } else if (num5 > num1 && num5 > num2 && num5 > num3 && num5 > num4){
- fifthNum = num5;
- }
- // end of firstNumber
- // start of fourthNumber
- if (num1 < num2 && num1 < num3 && num1 < num4 && num1 < num5){
- fourthNum = num1;
- }
- else if (num2 < num1 && num2 < num3 && num2 < num4 && num2 < num5){
- fourthNum = num2;
- }
- else if (num3 < num1 && num3 < num2 && num3 < num4 && num3 < num5){
- fourthNum = num3;
- }
- else if (num4 < num1 && num4 < num2 && num4 < num3 && num4 < num5){
- fourthNum = num4;
- }
- else if (num5 < num1 && num5 < num2 && num5 < num3 && num5 < num4){
- fourthNum = num5;
- }
- // end of fourthNumber
- // start of secondNumber
- if (num1 != firstNum && num1 != fourthNum && num1 != fifthNum){
- temp1 = num1;
- }
- if (num2 != firstNum && num2 != fourthNum && num1 != fifthNum){
- temp2 = num2;
- }
- if (num3 != firstNum && num3 != fourthNum && num1 != fifthNum){
- temp3 = num3;
- }
- if (num4 != firstNum && num4 != fourthNum && num1 != fifthNum){
- temp4 = num4;
- }
- if (num5 != firstNum && num5 != fourthNum && num1 != fifthNum){
- temp5 = num5;
- }
- if (temp1 > temp2 && temp1 > temp3 && temp1 > temp4 && temp1 > temp5){
- secondNum = num1;
- } else if (temp2 > temp1 && temp2 > temp3 && temp2 > temp4 && temp2 > temp5){
- secondNum = num2;
- } else if (temp3 > temp1 && temp3 > temp2 && temp3 > temp4 && temp3 > temp5){
- secondNum = num3;
- } else if (temp4 > temp1 && temp4 > temp2 && temp4 > temp3 && temp4 > temp5){
- secondNum = num4;
- } else if (temp5 > temp1 && temp5 > temp2 && temp5 > temp3 && temp5 > temp4){
- secondNum = num5;
- }
- // end of SecondNumber
- // Start of thirdNumber
- if (num1 != firstNum && num1 != secondNum && num1 != fourthNum && num1 != fifthNum ){
- thirdNum = num1;
- }
- else if (num2 != firstNum && num2 != secondNum && num2 != fourthNum && num2 != fifthNum){
- thirdNum = num2;
- }
- else if (num3 != firstNum && num3 != secondNum && num3 != fourthNum && num3 != fifthNum){
- thirdNum = num3;
- }
- else if (num4 != firstNum && num4 != secondNum && num4 != fourthNum && num4 != fifthNum){
- thirdNum = num4;
- }
- else if (num5 != firstNum && num5 != secondNum && num5 != fourthNum && num5 != fifthNum){
- thirdNum = num5;
- }
- // end of thirdNumber
- // start of fifthNum
- if (num1 != firstNum && num1 != secondNum && num1 != thirdNum && num1 != fourthNum){
- fifthNum = num1;
- }
- else if (num2 != firstNum && num2 != secondNum && num2 != thirdNum && num2 != fourthNum){
- fifthNum = num2;
- }
- else if (num3 != firstNum && num3 != secondNum && num3 != thirdNum && num3 != fourthNum){
- fifthNum = num3;
- }
- else if (num4 != firstNum && num4 != secondNum && num4 != thirdNum && num4 != fourthNum){
- fifthNum = num4;
- }
- else if (num5 != firstNum && num5 != secondNum && num5 != thirdNum && num5 != fourthNum){
- fifthNum = num5;
- }
- cout << "\n" << "The ascending order for the 5 numbers you just entered are: " << endl;
- cout << firstNum << " " << secondNum << " " << thirdNum << " " << fourthNum << " " << fifthNum << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement