The best way to do this is to actually SORT the numbers, not just PRINT them in sorted order.
Basically, for a program like this, you want to use the bubble sort technique (
http://en.wikipedia.org/wiki/Bubble_sort), except that you only have 3 variables to sort.
Bubble sort basically works by comparing adjacent values and swapping them if they are out of order. You start from the first two and when you get to the last two you start over again with the first two.
Example...
you start with:
4 7 3
First pass:
compare first two, 4 and 7
they are in order so you don't swap
you end with
4 7 3
compare second and third numbers, 7 and 3
they are out of order so you swap
you end with
4 3 7
Second pass:
compare first two, 4 and 3
they are out of order so you swap
you end with
3 4 7
After one "pass" you swap enough times such that the last number in the series is in the correct spot. The first pass you make two comparisons so 7 is in the correct spot at the end. The second pass you make one comparison (since 7 is already correct) so that 4 is in the correct spot. if 4 is in the correct spot then so is 3. Every pass you make one less comparison than the pass before because one more number ends up in the correct spot.
you make sum(n-1) comparisons to sort numbers using bubble sort
3 numbers - 3 comparisons
4 numbers - 6 comparisons
5 numbers - 10 comparisons
6 numbers - 15 comparisons
etc.
if you still don't understand see
http://en.wikipedia.org/wiki/Bubble_sort#Step-by-step_example
i hope you understand the basic concept of bubble sort such that later you can use loops to sort an undetermined amount of numbers
ill go ahead and give you some sample code so you can see its implementation better
Code:
int firstNum, secondNum, thirdNum;
cout << "Enter first number: ";
cin >> firstNum;
cout << "Enter second number: ";
cin >> secondNum;
cout << "Enter third number: ";
cin >> thirdNum;
int temp;
if (firstNum > secondNum)
{
temp = firstNum;
firstNum = secondNum; // these three lines swap firstNum and secondNum
secondNum = temp;
}
if (secondNum > thirdNum)
{
temp = secondNum;
secondNum = thirdNum;
thirdNum = temp;
}
if (firstNum > secondNum)
{
temp = firstNum;
firstNum = secondNum;
secondNum = temp;
}
cout << firstNum << " " << secondNum << " " << thirdNum; // to print all numbers sorted
cout << firstNum << " " << thirdNum; // to print min then max