how to get numbers in order

Hi, I'm doing this program where the user inputs 4 numbers and then it outputs the numbers in from the biggest to the least number. This is what I have si far . Can anyone help me with this please.


#include <iostream>
#include <fstream>
#include <string>
using namespace std;


#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
int x;
int y;
int z;
int w;

int n1, n2, n3, n4;
cin>>x>>y>>z>>w;




if(x>y){
if(x>z){
if(x>w){
n1 = x;
if(y>z){
if(y>w){
n2 = y;
if(z>w){
n3 = z;
n4 = w;
}else{
n3 = w;
n4 = z;
}
}else{
//y>z and w>y and w>z
//W>Y>Z>X
n1=w;
n2=y;
n3=z;
n4=x;


}
}else{
//z>y

n1=w;
n2=z;
n3=y;
n4=x;





}
}else{
//x>y and x>z and w>x>








}
}else{
//x>y and z>x and z>y





}
} else {
//y>x










}
cout<<n1<<n2<<n3<<n4;









cin.ignore(200, '\n');
int halt;
cin>>halt;

return 0;
}







Last edited on
Please use [code][/code] tags when posting code

You can get the four numbers in an array or in a container and use the sort function, that would make your program have only phew lines of code

http://www.cplusplus.com/reference/algorithm/sort.html
Last edited on
sorry if I didn't use the code tags, well, in mi program I don't wanna use &&,|| and things like that because that would be easier and I want to learn how to do it like that. I don't know how to keep doing it after the part where it says "}else{
//x>y and x>z and w>x> . coulf anyone tell me please.
why do you want to do it the hardest way possible?

use sort.

if you don't want to do that, then, for example, the minimum of n1, n2, n3, and n4 == min( min( n1, n2 ), min( n3, n4 ) )

tthanks to everyone. the thing is that I'm taking a c++ class for the first time and I don't know that much, that's why I want to learn that way.
Last edited on
If you want to become familiar with if() statements, fine. However if you are trying to "learn" (ie, memorize) the algorithm for arranging four numbers in some order then you will never be a good programmer.
Programming is an art form -- it is all about solving problems creatively.
Someone who can only solve problems by recalling some memorized
algorithm will never be a good programmer.
Topic archived. No new replies allowed.