Trouble with ordering array in least to greatest

Hi. I'm very new to C++, and I've tried here to order the array from least to greatest, but I get this output.


Enter 3 numbers, do not enter any negatives.
1
2
3
The order of your numbers from least to greatest is 1, 2, 1976242530.


I don't understand why it is doing this at all. This is the code.

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

using namespace std;

int main()
{
    int ordNums[3];
    int big, med, low = 0;

    cout << "Enter 3 numbers, do not enter any negatives." << endl;
    cin >> ordNums[0] >> ordNums[1] >> ordNums[2];

    for (int i = 0; i < 2; i++) {
        if (ordNums[i] > big){
            big = ordNums[i];}
    }

    for (int x = 0; x < 2; x++) {
        if (ordNums[x] < big){
            med = ordNums[x];}
    }

    for (int z = 0; z < 2; z++) {
        if (ordNums[z] < med){
            low = ordNums[z];}
    }

    cout << "The order of your numbers from least to greatest is " << low << ", " << med << ", " << big << "." << endl;
    return 0;
}
Last edited on
you 've only initialize low .
1
2
3
int big = 0;
int med = 0;
int low = 0;

or
1
2
int big,med,low;
big=med=low=0;
Topic archived. No new replies allowed.