I am using Alice 2.4 I have to create a program in which I place a character into a world and that character has to say an arrangement of numbers from lowest to highest. I have to use If/Else statements as well as being able to input any number and the character be able to arrange them from highest to lowest and give that as an output. I would really appreciate some help.
Do you know anything about sorting?
No, I'm afraid I'm not familiar with it. This is my first programming course.
@e.mccormick
If you store the information in an array, you should have a sort method.
If I may ask, how do you make an array. My instructor hasn't taught us anything about arrays yet.
Hmmm... OK. If yuou are not going to do it with an array, how were you supposed to save the numbers given?
Well, somehow, I'm supposed to be able to enter any number using an "ask user for a number" function and then have the program rearrange those numbers in order from lowest to highest. I'm rather lost on how to create this kind of program. The only help I received from my instructor was I needed to create 3 strings, 3 number variables, and 6 If/Else statements.
So is this program only supposed to work with three numbers, not some arbitrary set of numbers?
It can be any three numbers. It can be negative, decimals, etc. But it has to be three numbers arranged from lowest to highest.
This program can work with more than three numbers. The three numbers is my assignment.
Ah, OK, so for three numbers you don't nessisarily need an array. If it is meant to be able to take in anywhere form 2 to 65,000 numbers, you would need an array. See, when you limit the numbers to a fixed quantity, like 3, then you can make one variable for each.
Okay, I've set up one variable for each so far.
Let's call them a, b, and c. The if/else statements would be used to find out what is largest of the three. ``` if a > b if a > c if b > c print a, b, c else if b > c ``` just that lets you know a lot. With some careful work you can arrange things in a way where any combination will result in giving the answer properly.
And that is psudo-code, or fake code, to just show the concept. I know Alice does it differently.
Ah okay, that makes sense. Yeah, it's really confusing for me.
I'll give that an attempt. Thank you!
OK. At least now you have a little bit of an idea of how the 3 number variables and 6 If/Else statements are used. Not sure what the 3 strings are for. Probably to ask what the three numbers are.
Yeah, I had no idea what I was supposed to do with them. Thank you so much for teaching me!.
Also, if you think about it, there are only 6 orders: abc acb bac bca cab cba So you could do "and" checks as a worst case: ``` if a > b and b > c print a, b, c if a > b and c > b print a, c, b ```
Okay, thank you very much!
Join our real-time social learning platform and learn together with your friends!