Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

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.

OpenStudy (e.mccormick):

Do you know anything about sorting?

OpenStudy (anonymous):

No, I'm afraid I'm not familiar with it. This is my first programming course.

OpenStudy (anonymous):

@e.mccormick

OpenStudy (e.mccormick):

If you store the information in an array, you should have a sort method.

OpenStudy (anonymous):

If I may ask, how do you make an array. My instructor hasn't taught us anything about arrays yet.

OpenStudy (e.mccormick):

Hmmm... OK. If yuou are not going to do it with an array, how were you supposed to save the numbers given?

OpenStudy (anonymous):

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.

OpenStudy (e.mccormick):

So is this program only supposed to work with three numbers, not some arbitrary set of numbers?

OpenStudy (anonymous):

It can be any three numbers. It can be negative, decimals, etc. But it has to be three numbers arranged from lowest to highest.

OpenStudy (anonymous):

This program can work with more than three numbers. The three numbers is my assignment.

OpenStudy (e.mccormick):

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.

OpenStudy (anonymous):

Okay, I've set up one variable for each so far.

OpenStudy (e.mccormick):

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.

OpenStudy (e.mccormick):

And that is psudo-code, or fake code, to just show the concept. I know Alice does it differently.

OpenStudy (anonymous):

Ah okay, that makes sense. Yeah, it's really confusing for me.

OpenStudy (anonymous):

I'll give that an attempt. Thank you!

OpenStudy (e.mccormick):

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.

OpenStudy (anonymous):

Yeah, I had no idea what I was supposed to do with them. Thank you so much for teaching me!.

OpenStudy (e.mccormick):

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 ```

OpenStudy (anonymous):

Okay, thank you very much!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!