LOGIC PROBLEM?

I am doing a problem that prompts a user to enter 3 numbers
and arrange them in all 6 possible combinations
IE:
1-2-3|2-3-1
3-2-1|3-1-2
2-1-3|1-3-2

I know what im supposed to see using int variables 1,2,3.
But i seem to have a logical error that i cant spot.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  #include<iostream>
using namespace std;
int main()
{

int num1; 
int num2;
int num3;

cout<<"Enter first number"<<endl;
cin>>num1; 
cout<<"Enter second number"<<endl;
cin>>num2;
cout<<"Enter third number"<<endl;
cin>>num3;
cout<<endl;


//CASE #1
if ((num1>num2)&&(num2>num3)&&(num1<num3))
cout<<num3<<" "<<num2<<" "<<num1<<endl;


//CASE #2
if ((num1>num2)&&(num1>num3)&&(num2<num3))
cout<<num1<<" "<<num3<<" "<<num2<<endl;


//CASE #3
if ((num1<num2)&&(num1<num3)&&(num2>num3))
cout<<num1<<" "<<num2<<" "<<num3<<endl;

//CASE #4
if ((num1<num2)&&(num1>num3)&&(num2>num3))
cout<<num3<<" "<<num1<<" "<<num2<<endl; 

//CASE #5
if ((num1>num2)&&(num1<num3)&&(num2<num3))
cout<<num2<<" "<<num1<<num3<<endl; 

//CASE #6
if ((num2<num1)&&(num3<num1)&&(num2<num3))
  cout<<num2<<" "<<num3<<" "<<num1<<endl; 
  
  
  cout<<"Done";

return 0; 

any help would be greatly appreciated!!!
For one, on line 30, you check if num2 > num3, but then you print num2 before num3.
On line 20 you see if num1 < num3, but you print out num1 last.

If you're only hardcoding 3 elements, you could do this a lot simpler with nested if-statements.

You could also change the separate if-statements to a chain of if, else if, else if, else statements, and at the end, if your code ever goes inside your "else" statement, you know which numbers caused an error.

Edit: fixed line number
Last edited on
Will apply and check
Thank you!
Topic archived. No new replies allowed.