problem with arranging of variables..

Hi i'm new with C++ programming and i have given a school work to creat a program that the user will input 3 numbers and the out put will be arrange in descending orders and i can only used the if else or nested if else statement..

so here's the problem out the 6 combination im only getting 4 correct answers.. pls help me here is the code i made...

#include<iostream.h>
#include<conio.h>

int num1,num2,num3;

void main()
{clrscr();

cout<<" enter 3 digits: ";
cin>>num1>>num2>>num3;

if(num1<num2&&num2<num3)
{
cout<<num1<<num2<<num3;
}
else if(num1<num2&&num2>num3)
{
cout<<num1<<num3<<num2;
}
else if(num1>num2&&num2<num3)
{
cout<<num2<<num1<<num3;
}
else if((num1>num3)&&(num2))
{
cout<<num3<<num2<<num1;
}
else if(num1<num2&&num2<num3)
{
cout<<num2<<num1<<num3;
}
else if(num1<num2&&num2>num3)
{
cout<<num3<<num2<<num1;
}
getch();
}
Before we go any further, I can't help but notice that several of your if conditions match (see: if #2 and if #6, if #1 and if #5). You might want to iron that out.

Also, check if #4. There's something wonky with that one.

Finally, please replace void main() with int main(). void main(), though some compilers support it, is illegal. :/

-Albatross
Last edited on
#include<iostream>

using namespace std;

int main()
{
short num1,num2,num3;
char x[] = "The numbers in order: ";

cout << "Give me three numbers. "<<endl<<endl;
cout << "Input the first number and press Enter: ";
cin >> num1;
cout << "Input the second number and press Enter: ";
cin >> num2;
cout << "Input the third number and press Enter: ";
cin >> num3;

cout << "\n\nThank you! Your numbers are: "
<< num1 << " " << num2 << " " << num3<<endl<<endl;

if(num1 <= num2 && num2 <= num3)
cout << x << num1 << num2 << num3 << endl;
if(num2 <= num3 && num3 <= num1)
cout << x << num2 << num3 << num1 << endl;
if(num3 <= num1 && num1 <= num2)
cout << x << num3 << num1 << num2 << endl;
if(num3 < num2 && num2 < num1)
cout << x << num3 << num2 << num1 << endl;
if(num2 < num1 && num1 < num3)
cout << x << num2 << num1 << num3 << endl;
if(num1 < num3 && num3 < num2)
cout << x << num1 << num3 << num2 << endl;

return 0;
}
thx for the help...
Topic archived. No new replies allowed.