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: 
I've done something similar to this in a introduction to C++ class, so in case you need a **very** simple answer without using some of the more complex functions, I would have condensed it into something like this.

I find this to be a helpful way because it helped me to use complex relational operations (such as `&&`, `||`, `!=`) and it helps simplify some of the conditional statements so they don't end up becoming nested enough times for them to become confusing.

I think using those compound relational operations at the end to determine the smallest of the integers is helpful because it eliminates some of the comparisons in the original code, i.e. 
if `x` is not the smallest AND `x` is not the middle therefore `x` is the smallest.

```
#include <iostream>

using namespace std;

main () {

    int x, y, z;
    int largest, smallest, middle;

    cout << "Enter three integers separated by spaces: ";
    cin >> x >> y >> z;

    if (x > y) {
        if (x > z)
            largest = x;
        else
        if (x < z)
            middle = x;
    }

    if (y > x) {
        if (y > z)
            largest = y;
        else
        if (y < z)
            middle = y;
    }

    if (z > y) {
        if (z > x)
            largest = z;
        else
        if (z < x)
            middle = z;
    }

    if (y != largest && y != middle)
        smallest = y;
    if (x != largest && x != middle)
        smallest = x;
    if (z != largest && z != middle)
        smallest = z;

    cout << "Smallest = " << smallest << endl;
    cout << "Middle = " << middle << endl;
    cout << "Largest = " << largest << endl;

}

```
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 << " ";
}

```