Results 1 to 6 of 6
  1. #1
    Bentino is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Help needed with constructing a while loop

    Prompt the user for and read in the number of guesses the user wants at the random number.
    2. Generate (but not immediately display) the random number between 1 and 100.
    3. As long as the user has not yet guessed the random number and the number of guesses
    allowed has not been exceded:
    • Prompt the user to enter their next guess at the generated random number.
    • If the guess is smaller than the actual random number, print out a message indicating
    that the user’s guess is too small.
    • If the guess is larger than the actual random number, print out a message indicating
    that the user’s guess is too large.
    4. If the user succeeded in guessing the random number, then print out a congratulatory
    message and tell them how many guesses they took.
    5. If the user did not succeed in guessing the random number, the number should be displayed.



    so far this is what I have:


    Java Code:
    import java.util.*;
    
    public class SimpleGame {
    	
    public static void main(String args[])
    	{
    	int numGuess;
    	int userGuess;
    	
    	// Prompt User for Number of guesses as well as What guess the user intends to input
    	Scanner kbd = new Scanner(System.in);
    	System.out.print("How many guesses do you want?");
    	numGuess = kbd.nextInt();
    	
    	System.out.println("What is your guess?");
    	userGuess = kbd.nextInt();
    	
    	
    	while (numGuess == 1)
    		
    	{
    	       if (userGuess == 63)
    	    	   System.out.print("Congratulations, you guessed the number right!");
    	       else if (userGuess >= 63)
    	    	   System.out.println("Sorry, your guess is too high");
    	       else if (userGuess <= 63)
    	    	   System.out.println("Sorry, your guess is too low");
    	           System.out.println("The number was 63");
    	       break;
    	       
    	}		 
    	
    while (numGuess == 2)
    		
    	{
    	       if (userGuess == 36)
    	    	   System.out.print("Congratulations, you guessed the number right!");
    	       else if (userGuess >= 36)
    	    	   System.out.println("Sorry, your guess is too high");
    	       else if (userGuess <= 36)
    	    	   System.out.println("Sorry, your guess is too low");
    	           System.out.println("The number was 36");
    	       userGuess += 2;
    	       numGuess += 2;
    	       break;
    	       
    	}

  2. #2
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,761
    Rep Power
    7

    Default Re: Help needed with constructing a while loop

    Do you have a question?

  3. #3
    Bentino is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: Help needed with constructing a while loop

    I need help with getting it to prompt me 8 times.

  4. #4
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Re: Help needed with constructing a while loop

    This is a really bad example of a game.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help needed with constructing a while loop

    Quote Originally Posted by rokit boy View Post
    This is a really bad example of a game.
    Not helpful.

  6. #6
    Bentino is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: Help needed with constructing a while loop

    here is the thing, when i run this, its prompts me once so i am a little confused as to how i may get it to prompt me, 2 0r 3 0r 4...etc times in a row so that is my issue, if anyone could assist me, it would be much appreciated.

    thanks

Similar Threads

  1. Constructing a HashMap
    By azalea in forum New To Java
    Replies: 2
    Last Post: 11-03-2011, 03:19 PM
  2. help needed plz with some loop problem I guess
    By Tommeke in forum New To Java
    Replies: 6
    Last Post: 07-21-2011, 07:42 PM
  3. Problem with constructing an ArrayList
    By Diplo in forum New To Java
    Replies: 5
    Last Post: 12-07-2009, 03:52 PM
  4. Constructing the Interface!
    By myskynim in forum New To Java
    Replies: 3
    Last Post: 11-19-2009, 09:51 AM
  5. Need help with constructing code
    By Nine0joe in forum New To Java
    Replies: 6
    Last Post: 05-09-2008, 02:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •