Need help with rearrangement

I was going to create a program that rearrange numbers from smallest to biggest.
But it doesn't work can anybody help me on this?
I'm still a beginner and haven't learned vectors and other stuff yet.

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>

using namespace std;

int main()
{
    int alpha=0;
    int beta=0;
    int gamma=0;
    int smallest=0;
    int biggest=0;
    int middle=0;
    cout << "Please enter three integer values separated by a space: ";
	cin >> alpha >> beta >> gamma;
	if (!cin){
	cout << "values read : " << alpha << ", " << beta << ", " << gamma <<'\n';
	}
    if(beta>=alpha && gamma>=alpha)
    {
        smallest=alpha;
        if(beta>=gamma)
        {
            beta=biggest;
            gamma=middle;
        }
        else
        {
            beta=middle;
            gamma=biggest;
        }

    }
    else if(gamma>=beta && alpha>=beta)
    {
        smallest=beta;
        if(gamma>=alpha)
        {
            alpha=middle;
            gamma=biggest;
        }

        else
        {
            alpha=biggest;
            gamma=middle;
        }
    }

       else
    {
        smallest=gamma;
        if(alpha>=beta)
        {
            alpha=biggest;
            beta=middle;
        }

        else
        {
            alpha=middle;
            beta=biggest;
        }
    }

    cout <<smallest<<", "<<middle<<", "<<biggest;
    return 0;
}
Most of your assignment statements are the wrong way round.

Line 20 reads:
smallest = alpha

This is the right way round.
You've identified that alpha is the smallest value and you now want that value to be assigned to the variable 'smallest'.

But Line 23 reads
beta = biggest;

This isn't what you want.
You've identifed that beta is the biggest value and you want that value assigned to the variable 'biggest'.

In order to do that, you need to write the following:
biggest = beta;.

(In an assignment statement, the variable on the left hand side is being given the value on the right.)

Most, but not all, of your assignment statements simply need switching round.

I'm a noob too, so not great at explaining stuff in technical way, but hopefully this helps.
I will try to explain what printf told you.

In your code it had alpha, beta, and gamma. so on line 20, smallest = alpha means that alpha's value will be given to smallest. but if you do beta = biggest, you are giving BETA the value of biggest, which is 0, and it will NOT care about the previous value you asked the user to input in.

Hope that helps.

EDIT:added a NOT behind the will
Last edited on
Thanks Guys.
Topic archived. No new replies allowed.