I also noticed similar errors to what michelle mentioned. Your random number generator must be placed outside of your checking loop, otherwise it will generate a new number after each guess. Also I could not find where you created the random number object:
Random generator = new Random();
You have to declare a new object before you can instantiate it. Were you getting compile errors?
finally, when you use Keyboard.readString() to get a y or n (I would suggest read char), it needs to be inside your outer loop. The do while loop looks for a Y, but the way you have it it looks for it before the user has a chance to enter.
I hope this helps somewhat, although I imagine you have worked through much of this by now.
Ken W
On 2/7/2003 5:55:19 PM, Isaac Scribner wrote:
>hello all,
>
>for what ever reason I can't
>seem to get this code to work.
>I'm working on 3.11, and I
>can't seem to get it to repeat
>it's self.
>Mr. Ross told me this
>advice...
>1. outer loop: controls
>playing a game and going again
>2. inner loop -- controls a
>single game of guessing the
>number
>
>It sure looks like that's what
>I did but to ill effect
>
>import cs1.Keyboard;
>public class HiLowGame
>{
>public static void main
>(String[] args)
>{
>int randomNumber;
>int guess;
>int tries = 0;
>String done = "n";
>do // outer loop
>{
>do // inner loop
>{
>randomNumber = (int)
>(Math.random () * 100) + 1;
>System.out.println
>(randomNumber); // for testing
>purposes
>
>System.out.print ("Guess a
>number between 1 and 100 : ");
>guess = Keyboard.readInt();
>tries++;
>
>if (guess < randomNumber)
>System.out.println ("Your
>guess is to low");
>
>if (guess > randomNumber)
>System.out.println ("Your
>guess is too high");
>}
>while (guess !=
>randomNumber);//inner loop
>System.out.println ("It took
>you " +tries+ " tries to guess
>the correct number");
>}
>while (done == "y"); //outer
>loop
>
>System.out.print ("Play again
>y/n ?");
>done = Keyboard.readString();
>}}
>
>
>do you guys have and other
>help for me?
>
>Isaac