aspose file tools*
The moose likes Beginning Java and the fly likes GuessingGame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "GuessingGame " Watch "GuessingGame " New topic
Author

GuessingGame

kofi ofei
Ranch Hand

Joined: May 22, 2005
Posts: 39
could i get help in getting this program to work. there are two errors. thanks


public class GuessingGame {

public static void main(String[] args) {
System.out.println("Let's play a game. I'll pick a number between");
System.out.println("1 and 100, and you try to guess it.");
boolean playAgain;
do {
playGame(); // call subroutine to play one game
System.out.println("Would you like to play again? ");
playAgain = getlnBoolean();
} while (playAgain);
System.out.println("Thanks for playing. Goodbye.");
} // end of main()

static void playGame() {
int computerNumber; // A random number picked by the computer.
int usersGuess; // A number entered by user as a guess.
int guessCount; // Number of guesses the user has made.
computerNumber = (int)(100 * Math.random()) + 1;
// The value assigned to computerNumber is randomly
// chosen integer between 1 and 100, inclusive.
guessCount = 0;
System.out.println();
System.out.println("What is your first guess?");
while (true) {
usersGuess = getInt(); // get the user's guess
guessCount++;
if (usersGuess == computerNumber) {
System.out.println ("You got it in" + guessCount
+ " guesses! My number was " + computerNumber);
break; // the game is over; the user has won
}
if (guessCount == 6) {
System.out.println("You didn't get the number in 6 guesses.");
System.out.println("You lose. My number was " + computerNumber);
break; // the game is over the user has lost
}
// If we get to this point, the game continues.
// Tell the user if the guess was too high or too low.
if (usersGuess < computerNumber)
System.out.println("That's too low. Try again: ");
else if (usersGuess > computerNumber)
System.out.println("That's too high. Try again: ");
}
System.out.println ();
} // end of playGame ()

} // end of class GuessingGame
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hi,
Well I guess you have posted this question in the wrong forum, and it is so hard to read the code like this, please use the UBB Code when you are pasting the java code. Further more, please do tell us what are the errors, it is much easier for us then to answer. Regards.


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i posted mine at beginner´┐Żs


java amateur
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Moving this to the Java In General (Beginner) forum.

Please try to post your questions n the most appropriate forum. Since this forum is about J2ME and you have code that has public static void main. Means that it is not a question about J2ME.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Quite simple really. You are not reading the user input. You have two methods getlnBoolean() and getInt() which are meant to read the user input but are not defined anywhere.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GuessingGame