How to sort 3 integer




I'm studying C++ by 3 weeks and I'm reading : programming priciples and practices using C++.At chapter 3 I have to write a program for this problem :

Write a program that prompts the user to enter 3 integer values, and then outputs the values in numerical sequence separated by commas. So: if the user enters the values 10 4 6, the output should be 4, 6, 10. If two values are the same, they should just be ordered together. So, the input 4 5 4 should give 4, 4, 5.

My problem is that if I go to check the solution of the problem on the official website of Stroustrup its code uses the same facilities that the book I'm not quite tought. How would you solve this problem? The author din't teach me how to use a compound statement so i can't find an another solution to resolve this problem.
- Get first number, set it as first
- Get second number, and compare it to first, if smaller it is now first and first one is now second, other wise set it as second
- Get third number, compare it to first, if smaller print third number and first and second in that order. Else compare it to second, if smaller, print first, third, and second in that order. If nothing works, just print first, second, and third
@Smac89 can i do it without a compound if statement ?
Yes you can. I put the if-statements there as a generic method for solving the problem for small number of values. If you want to solve it iteratively, you can implement a sorting function using either one of bubble sort, selection sort, insertion sort. Typing any one of those into google should show you how to implement either one you choose
Topic archived. No new replies allowed.