High Low Game in Java Play Again

#1

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: half-dozen
  • Joined: 17-June 14

How to add together play over again selection to Hullo Lo game

Posted 17 June 2014 - 01:07 PM

I am a beginner programmer. My task is to write a program that plays the "How-do-you-do Lo guessing game." The program runs smoothly. Yet, it does not proceed to the next game after the previous game is done. I need to add a "play once more" choice to the programme and then that the user will continue to play until they accept called to quit. I have tried several different ways but each ane has failed. I am completely stuck on this. I have fastened my code to this. Help is greatly appreciated.


Is This A Good Question/Topic? 0

  • +

#two andrewsw User is offline

Reputation: 6957

  • View blog
  • Posts: 28,696
  • Joined: 12-Dec 12

Re: How to add play again choice to Hello Lo game

Posted 17 June 2014 - 01:eleven PM

Your lawmaking isn't included. Post it here, betwixt code-tags.

#3 a_alex User is offline

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: 6
  • Joined: 17-June xiv

Re: How to add play once again choice to Howdy Lo game

Posted 17 June 2014 - 01:11 PM

I apologize if my code does not show up. I'm new to this site and I'm not sure how to post code correctly.
this is my code:

import java.util.Random;
import java.util.Scanner;

public class HiLo
{
public static void master (String[] args)
{

final int MAX = 100;
int reply, guess;
int numberOfTries = 0;

Scanner Keyboard = new Scanner(System.in);

{
System.out.impress("Guess a number from 1 to "
+ MAX + " (or enter 0 at any time to quit): ");
guess = Keyboard.nextInt();
}

Random generator = new Random();
respond = generator.nextInt(MAX) +ane;

while (guess != answer && gauge != 0)
{

if (approximate > answer && guess != 0)
{
System.out.print("Too high! Guess once more:");
guess = Keyboard.nextInt();
}

if (guess < reply && guess != 0)
{
System.out.print("Besides Low! Guess again:");
guess = Keyboard.nextInt();
}

if (guess == 0)
{
Organization.out.print("You gave upwardly subsequently " + " " + numberOfTries + " " + "guesses.");
System.out.print("The secret number was " + answer);
gauge = Keyboard.nextInt();
}

numberOfTries=numberOfTries+ane;

}

if (guess == answer)
{
System.out.impress("Correct!");
System.out.println("It took you " + " " + numberOfTries + " " + "guesses");
System.out.println();
System.out.impress( "Play again(Y/N)?");
}
}
}

#iv andrewsw User is offline

Reputation: 6957

  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: How to add play again option to Hullo Lo game

Posted 17 June 2014 - 01:17 PM

This screencast volition show you lot the way:

http://screenr.com/w9TN

#5 a_alex User is offline

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: six
  • Joined: 17-June 14

Re: How to add play again choice to Hullo Lo game

Posted 17 June 2014 - 01:20 PM

import java.util.Random; import java.util.Scanner;     public class HiLo    {     public static void primary (Cord[] args)      {          final int MAX = 100;      int answer, guess;      int numberOfTries = 0;     Scanner Keyboard = new Scanner(System.in);          {      Organisation.out.impress("Judge a number from 1 to "                        + MAX + " (or enter 0 at any time to quit): ");      guess = Keyboard.nextInt();      }       Random generator = new Random();      answer = generator.nextInt(MAX) +1;        while (judge != answer && gauge != 0)      {       if (guess > answer && guess != 0)      {       Organisation.out.print("Too high! Judge again:");       gauge = Keyboard.nextInt();      }       if (gauge < answer && estimate != 0)      {       System.out.impress("Too Depression! Guess again:");        gauge = Keyboard.nextInt();      }       if (guess == 0)      {       Organisation.out.print("You gave upward subsequently " + " " + numberOfTries + " " + "guesses.");       Organization.out.impress("The secret number was " + answer);       guess = Keyboard.nextInt();      }       numberOfTries=numberOfTries+1;            }       if (guess == answer)     {      Organisation.out.print("Correct!");      Organization.out.println("It took you lot " + " " + numberOfTries + " " + "guesses");      System.out.println();      System.out.print( "Play again(Y/North)?");     }   } }            

#half-dozen andrewsw User is offline

Reputation: 6957

  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: How to add play again selection to Howdy Lo game

Posted 17 June 2014 - 01:33 PM

Arrangement.out.print( "Play again(Y/North)?");            

You currently don't do anything later this line.

The whole section that needs to echo might be in a practice-while loop. You could read a character (at the bottom of the loop) and check this character to decide whether to go once more:

do {      // read a character, stored as 'again' } while (once more == 'y' || again == 'Y');            

You might read a string, rather than a character. There are a few approaches.

This post has been edited by andrewsw: 17 June 2014 - 01:35 PM

#7 a_alex User is offline

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: 6
  • Joined: 17-June 14

Re: How to add play again option to Hi Lo game

Posted 17 June 2014 - 02:45 PM

I'1000 not certain where i would add that within the code.

#8 andrewsw User is offline

Reputation: 6957

  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: How to add play again choice to Hello Lo game

Posted 17 June 2014 - 02:56 PM

Around the whole section that needs to repeat.

#9 a_alex User is offline

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: half-dozen
  • Joined: 17-June fourteen

Re: How to add together play again choice to Howdy Lo game

Posted 17 June 2014 - 04:41 PM

Thank you lot for the help. information technology was profoundly needed. unfortunately, the teacher said to get rid of the line where it asks to play again. It should automatically proceed to the side by side game after the user has guessed the correct code. I fabricated some revisions to the code but now i am stuck again trying to figure out what needs to be added in social club for the code to proceed later on the right guess. Again, thank you for your help.

import java.util.Random; import java.util.Scanner;     public form HiLo    {     public static void main (String[] args)      {          terminal int MAX = 100;      int answer, approximate;      int numberOfGuesses = 0;     Scanner Keyboard = new Scanner(System.in);      {      Arrangement.out.print("Approximate a number from 1 to "                        + MAX + " (or enter 0 at any fourth dimension to quit): ");      gauge = Keyboard.nextInt();      }       Random generator = new Random();      reply = generator.nextInt(MAX) +1;        while (guess != answer && guess != 0)      {       if (gauge > reply && guess != 0)      {       System.out.print("Besides high! Gauge again:");       judge = Keyboard.nextInt();      }       if (judge < respond && guess != 0)      {       System.out.print("Too Low! Guess again:");        guess = Keyboard.nextInt();      }       if (guess == 0)      {       System.out.impress("You gave up afterwards " + " " + numberOfGuesses + " " + "guesses.");       System.out.print("The secret number was " + answer);       gauge = Keyboard.nextInt();      }       numberOfGuesses=numberOfGuesses+1;            }       if (guess == respond)      {      System.out.print("Right!");      System.out.println("Information technology took you lot " + " " + numberOfGuesses + " " + "guesses");     }   } }            

#10 cilaes User is offline

  • D.I.C Head

Reputation: 9

  • View blog
  • Posts: 75
  • Joined: 12-Dec 11

Re: How to add play once more choice to Hi Lo game

Posted 22 June 2014 - 07:05 AM

Alex, these gentlemen aren't hither to complete your homework for y'all. Andrew's solution will work regardless whether you get user input or not.

do {    // This lawmaking volition run every bit long as the condition is TRUE } while (True);            

Y'all could also wrap everything yous want to loop in a while(Truthful) loop.

This post has been edited by cilaes: 22 June 2014 - 07:05 AM

steptoedeppoccanot.blogspot.com

Source: https://www.dreamincode.net/forums/topic/348846-how-to-add-play-again-choice-to-hi-lo-game/

0 Response to "High Low Game in Java Play Again"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel