Alice Community How do I get out of the "While" Method?

 How do I get out of the "While" Method?
Hoshi_Kawa
Guest

Status:
Posts: n/a
How do I get out of the "While" Method? - 10-16-2006, 08:36 AM

I'm currently in class, and were trying do question #10 for Chapter 5, where we have to create a Alice Guessing game.

Apparently while trying to use the "While" method we cannot come out of it. My teacher was able to get it to work on her computer, but she's showing us how she did it, but it's still not comming out of the "While" Method for us.

Our teachers program is called random number.a2w

mine is GuessNumber.a2w

can anyone help us out?
Attached Files
 random number.a2w (1.59 MB, 436 views) GuessNumber.a2w (390.5 KB, 437 views)

 DrJim Guest   Status: Posts: n/a 10-16-2006, 07:15 PM This looks like another case (see http://www.alice.org/community/showt...=1306#post1306 ) of Alice using integers but not allowing them as a data type (see bug list on the main Alice page). You can solve your problem by multiplying the random number by 1.0 (not 1) which will convert it to double precision (or floating point) and your program should work fine - at least it did for me. I can't see any reason your teacher's program doesn't have the same problem, but it also worked for me without any changes - anyone else see the difference?
 I believe the cause is rooted in the way alice compares numbers
 newdok Guest   Status: Posts: n/a I believe the cause is rooted in the way alice compares numbers - 12-01-2006, 08:22 PM a bit of background is nessesary. Alice stores the Number data type as a "double precision floating point number" (aka a double), and the troublesome thing about floating point comparisons is that due to the underlying implementation of floating point numbers, numbers that are extremely close might not actually be equal. anyways when i learned C a few years back, we had to deal with similar issues. What they taught us was to never compare floating point numbers for equality directly. Instead, subtract the smaller from the larger, and see if that value is less than some known quantity. Note that you have to get the sign right or else you'll end up with it being true if the second number is greater than the first number by not less than epsilon. //example: /** *@author John O'Meara * example of a proper equality comparison for floating point numbers... */ public Boolean areNumbersEqual(Number a, Number b) { Number ZERO_TOLERANCE = 0.01; // ^note: set this to a sufficently low value //for whatever your purposes are( - in otherwords, this should be larger //than any difference values that you care to differentation between. if (a > b) { return ((a-b)
 Shadow Sovereign Guest   Status: Posts: n/a 12-01-2006, 09:24 PM Newdok, your avatar has some code that looks somewhat familiar to me... where have I seen that before? I'm not sure what you're asking here, Hoshi-Kawa... are you trying to use a random number to find a certain integer within a limited scale, or just a wildly random number, or something?( ) Not sure if I'm being much help...

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge