Question: I'm a C++ beginner and I was told to make a program to arrange three integers from least to greatest. How did I do?

```
#include <iostream>

using namespace std;

int main()
{
    int x = 0;
    int y = 0;
    int z = 0;
    int first = 0;
    int second = 0;
    int third = 0;
    cout<<"Enter three integers to be arranged from least to greatest.\n";
    cin>>x>>y>>z;

    if(x <= y)
    {
        if(x <= z)
        {
            first = x;
            if(y <= z)
            {
                second = y;
                third = z;
            }
            else
            {
                third = y;
                second = z;
            }
        }
        else
        {
            second = x;
            if(y <= z)
            {
                first = y;
                third = z;
            }
            else
            {
                third = y;
                first = z;
            }
        }
    }
    else
    {
        if(x <= z)
        {
            second = x;
            if (y <= z)
            {
                first = y;
                third = z;
            }
        }
        else
        {
            third = x;
            if ( y <= z)
            {
                first = y;
                second = z;
            }
            else
            {
                second = y;
                first = z;
            }
        }
    }
    cout<<first<<second<<third;
}

```

Answer: 
1. [`using namespace std;` is harmful](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice).
2. Don't define a variable before you need it. Remember you need to keep them all in mind when reading the code.
3. Don't initialize a variable before you have data to put there, as that suppresses compiler-warnings.
4. Don't try processing inputs you didn't actually receive, so check the state of the stream before sorting (You only need to do it once after trying to read all inputs).

```
if(!std::cin) {
    std::cout << "Error: Bad input.\n";
    return EXIT_FAILURE;
}

```
5. For sorting such a small and fixed number of inputs, [a sorting-network](https://en.wikipedia.org/wiki/Sorting_network) is best (unless swapping is *expensive*, in which case you would first generate the minimal number of swaps):

```
static void swap(int& a, int& b) {
    int t = a;
    a = b;
    b = t;
}
static void sort2(int& a, int& b) {
    if(a > b)
        swap(a, b); // Normally use std::swap from <utility>
}

sort2(first, second);
sort2(first, third);
sort2(second, third);

```

Generally, you would use a library-routine for sorting a range: `std::sort`.
6. I suggest you print *some* separator between the numbers you output, probably a single space:

```
std::cout << a << ' ' << b << ' ' << c << '\n';

```

Anyway, congratulations on using good formatting, even if not my preferred style. Too many beginners don't get how much that eases understanding and writing code.
As other answers nicely clarify other aspects, I will only focus on the sorting part. When you feel ready for it, have a look at the data structures provided by the language libraries. In particular, [`std::multiset`](http://en.cppreference.com/w/cpp/container/multiset) is appropriate here (as it is possible for two or more values to be equal), and it does the dirty work for you.

Example:

```
#include <iostream>
#include <set>

int main()
{
  int x = 0;
  int y = 0;
  int z = 0;
  std::cout << "Enter three integers to be arranged from least to greatest.\n";
  std::cin >> x >> y >> z;

  std::multiset<int> s = { x, y, z };

  for (int elem : s)
    std::cout << elem << " ";
}

```