Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
HiLo game
Old
rmille2
Guest
 
Status:
Posts: n/a
Default HiLo game - 12-10-2008, 08:32 PM

I have students writing a simple HiLo game where they generate a random number from 1 to 100 and then some object tries to guess it. Sometimes when the guess is equal to the number and the two are compared in a while loop (while guess != number) the loop keeps going and the bject says too high or too low. How can I remedy this situation?
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 12-11-2008, 06:11 PM

The random number generator occasionally doesn't generate an integer even when it is supposed to (a bug listed in the official bug list). This doesn't always happen (in one class I know of, for a specific program only about 4 people out of 20 had a problem) so it can be very discouraging to debug.

The fix is to basically multipy the result from the random number generator by 1.0 before making the test - for more detail do a forum search or look at the bug list on the Alice home page.
   
Reply With Quote
Reply

Thread Tools
Display Modes

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 Jump



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