Alice Community  

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

Thread Tools Display Modes
Intro to Programming Using Alice
Posts: n/a
Default Intro to Programming Using Alice - 04-12-2009, 08: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
Reply With Quote
Posts: n/a
Default 04-27-2009, 08: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.
Reply With Quote

while tile sentinel loop

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 ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.