in reply to Check this code please?
Hint 1: Your script has 10 lines where the user has to type in numbers. Obviously too much when he should type in only 5
Hint 2: Sorting the numbers is hell if you have them in single variables (i.e. $a,$b,$c...). I'm sure your teacher showed you how to use arrays. You need them here
Hint 3: You could simply use the function sort() as kcott said. But if you want or need to sort without using that function, you will need loops, otherwise sorting the numbers is still hell
Hint 4: There are a lot of methods to sort numbers (or anything else sortable). Do you know one? If not, think of how you would do it if you had them on paper and would have to sort them by hand, but could only see one number at a time (or compare and switch two numbers at a time).
Generally most sorting algorithms do that in two steps: 1. Go through all numbers and do something so that the numbers are sorted a little better 2. Repeat step 1 until step 1 can't make the order any better. Note that both steps are loops, step 1 the inner loop, step 2 the outer loop.
|
|---|