0

Ascending order of 3 numbers without array

Hello everyone, I've recently started to learn programming in C++, recently as in exactly 8 days so far. For my problem, I am given 3 random numbers that don't have to be unique and I have to ascend them in order from lowest to higher ( i forgot to mention the part that english is not my first language and if I didn't explain something right pls let me know) here's what I've tried so far : #include <iostream> using namespace std; int main() { int a=3, b= -1, c=20; cin>>a>>b>>c; if (a<=b) { cout << a << " " << b <<" "<< c; } else if (b<=c) { cout << b << " " << a <<" " << c ; } return 0; } as you can tell this is not right, well, its right for some numbers but not for all the numbers. on the cout it has to show only 3 number in ascending order and nothing else, for some numbers it will show like 10 digits and thats because I don't know yet how to stop that and only show in consol what i need. this is becoming way too long so I'l cut it off What am i doing wrong, what else can I try and what am I missing here? I can use also the && symbol besides this and the symbols shown above I cant use something else. p.s I dont want someone to type the whole code as it will not help me in any way.

10th Dec 2020, 7:23 PM
Yela
2 Respuestas
0
Use the min and max function...remember you can nest them, and a little bit of maths to output the middle value. You might have to #include algorithm header, although.. I have see it work without it.....(might be included in iostream.).
10th Dec 2020, 8:10 PM
rodwynnejones
rodwynnejones - avatar
0
i can't use that function. i can only use " if, else if, &&, <, <= and thats about all i can use
10th Dec 2020, 8:57 PM
Yela