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: 
Excess code
===========

You have some excess code in places where certain `if` statements are guaranteed to be true. The first is when `z < x < y`, you reach this code:

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

This could be simplified to:

```
    else
    {
        first = z;
        second = x;
        third = y;
    }

```

because the two `if` statements leading up to this block already guarantee this ordering.

Later on there is something similar where this code:

> 
> 
> ```
>     if(x <= z)
>     {
>         second = x;
>         if (y <= z)
>         {
>             first = y;
>             third = z;
>         }
>     }
> 
> ```
> 
> 

could be simplified to:

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

```

Since you are a beginner, I will only briefly mention that the code could be smaller and cleaner if you used more advanced things like arrays, loops, and functions.
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 << " ";
}

```