PDA

View Full Version : Intro to Programming Using Alice


gibs7usa
04-12-2009, 07:43 PM
I am working on "An Introduction to Programming Using Alice" Exercise 10 on Page 151: Creating a Guessing Game world
I have to create a world that asks the user to guess a random number of the computer's choice. There are 2 characters in the world, one tells you if the number is too high and one tells you if the number is too low.
The computer should keep asking you to guess until you guess the correct number.
My problem is that it keeps asking me to guess a number even after I guess the correct number.
I have to set up a sentinel loop so this doesn't happen, but I can't figure out how. I have reviewed the book, but maybe I am putting the wrong thing inside the While Tile
Thanks!

HisWorld
04-27-2009, 07:05 AM
Since I don't have this book I can't be certain, however having programmed something simliar in other languages I believe all you need is an additional if-else statement inside your loop.

I would think having three if else statements inside of one loop would be sufficient.
One to tell user if to high, and one to tell if to low, both not breaking out of the loop, finally one that is just right and has a method call.

A second solution would be to use a while statement such as
while answer =! correct.answer{


}
which would break the loop once a correct answer was given and go to your next line of code.