• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GuessingGame

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i posted mine at beginner�s
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic