+ 3

How can I sort three numbers in decreasing order?

The user is gonna give me values to three variables: A, B C. But there's a problem... I want A to be the largest number, B the second largest and C the smallest. But what if the user types 3 4 5 or 4 5 3 instead of 5 4 3? I want the program to reorganize the numbers in decreasing order, so if the user types 3 4 5, the program will make A be 5, 4 be B and 3 be C, regardless of the original order. I want the solution using c++. Please, help me :)

9th Apr 2020, 1:22 AM
Açucena Ribeiro
Açucena Ribeiro - avatar
8 Antworten
+ 2
You can write some simple statements to check the values and rearrange before you move into the core part of your program. ex: if(A<B) { int temp = A; A = B; B = temp; } if(A<C) { temp = A; A = C; C = temp; } if(B<C) { temp = B; B = C; C = temp; }
9th Apr 2020, 6:03 AM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 3
Thank you
9th Apr 2020, 1:32 PM
Amjad Abd Al Hussien
Amjad Abd Al Hussien - avatar
+ 1
its just a temporary integer variable to store the original value of A (or B) so you can get your values reassigned in the order you want them in. you can call it whatever you want. temp, t, heythere
9th Apr 2020, 6:27 AM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 1
Thank you 😃
9th Apr 2020, 6:29 AM
Açucena Ribeiro
Açucena Ribeiro - avatar
0
https://code.sololearn.com/cTEuTsIl4Vgg/?ref=app Here's my code. What should I write?
9th Apr 2020, 5:30 AM
Açucena Ribeiro
Açucena Ribeiro - avatar
0
Hi, Elizabeth. What's temp?
9th Apr 2020, 6:14 AM
Açucena Ribeiro
Açucena Ribeiro - avatar
- 2
look at your object spefulyiers and find the objected type
9th Apr 2020, 5:25 AM
samuel sandvig
samuel sandvig - avatar