Please help me understand/fix this.

I made the mistake of taking this intro c++ class and I am incredibly frustrated and confused.

I am supposed to be putting 6 numbers in order from smallest to largest but we're not allowed to use arrays, only if statement. How the heck do I get them to print out from smallest to largest if I enter 6 5 4 3 2 1.

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
 #include <iostream>

using namespace std;

int main()
{
    int a1,b1,c1,d1,e1,f1,hold;
    cout<<"Enter 6 more numbers: "<<endl;
    cin>>a1>>b1>>c1>>d1>>e1>>f1;
    hold = a1;
    if(a1 > b1){
        a1 = b1;
        b1 = hold;
    }
    if(b1 > c1){
        b1 = c1;
        c1 = hold;
    }
    if(c1 > d1){
        c1 = d1;
        d1 = hold;
    }
    if(d1 > e1){
        d1 = e1;
        e1 = hold;
    }
    if(e1 > f1){
        e1 = f1;
        f1 = hold;
    }

    cout<<a1<<b1<<c1<<d1<<e1<<f1;
}
This sounds like a job for a sorting algorithm the simplest one would probably be bubble sort. you can Google different examples on what bubble sort is and how to implement it. Another simple one would be insertion sort. you can Google insertion sort to get more info too.
Topic archived. No new replies allowed.