Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Variable not equal to 0 (http://www.alice.org/community/showthread.php?t=9857)

dapsenite 01-20-2013 07:54 PM

Variable not equal to 0
 
1 Attachment(s)
Hi all,

I'm very new to programming and I have a course assignment wherein I need to have an error message appear if the user input is equal to zero. I've attached the file with the assignment completed, but I can't figure out how to use the alice interface to continue asking for the speed and distance variables if the user enters 0.

Help! And thanks in advance for your expertise!

djslater107 01-21-2013 08:18 AM

variable equal to 0
 
1 Attachment(s)
Set up a while loop... Assume you have a distance variable and a speed variable... Also comparing a variable for equality to zero is very difficult when dealing with real numbers, and so I am going to assume a minimum speed and minimum distance value that the user has to enter.

while (either speed < 1 or distance < 1 or both)
ask user for speed
ask user for distance

The functions and operators you are looking for are in world functions tab

See the attached screen shot

chickentree 01-21-2013 04:20 PM

You need to ask the user for a number.
Look at World->function-> ask user (just under string functions.)

Judging from what is there already, adding this should not be a problem.

Mark

dapsenite 01-21-2013 07:23 PM

Thank you both for your help! I wasn't sure how to use that logic until I saw the "while" command. Thanks again!


All times are GMT -5. The time now is 03:53 PM.

Copyright ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.