tjarmon52's Profile User Rating: -----

Reputation: -2 Dishonored
Group:
New Members
Active Posts:
4 (0.01 per day)
Joined:
09-October 12
Profile Views:
48
Last Active:
User is offline Oct 25 2012 02:32 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   tjarmon52 has not set their status

Posts I've Made

  1. In Topic: guessing game

    Posted 9 Oct 2012

    I have to make a guessing game using java this is what i have so far. Im having a hard time trying to figure out how to keep track of the numbers so i can compare them. For example if the random number is 62 and the user enters 34 it needs to say too low but if the user then enters 32 after 34 it needs to say something like if 34 is too low 34 is also too low. And im also need help when i print out do you want to play again (y/n) i dont know how to make it play the game again. Please help!!!!



    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner keyboard= new Scanner(System.in);
    int secretNumber=(int) (Math.random()* 99 + 1);
    int numberOfTries=0;
    int max=0;
    int min=0;
    boolean win= false;
    String yes= "y";
    String no= "n";

    int round=0;
    while(round>=0){
    round++;

    while (win == false){
    System.out.println("Guess a number: ");
    int guess=keyboard.nextInt();
    numberOfTries++;



    if (guess>100){
    System.out.println("Huh? Your guess should be between 1 and 100");
    }
    else if (guess==secretNumber){
    win= true;
    }
    else if (guess < secretNumber){
    if(guess<=0){
    System.out.println("Huh? Your guess should be between 1 and 100");
    }else
    System.out.println(guess + " is too low");
    }
    else if (guess > secretNumber){
    System.out.println(guess + " is too high");
    }
    }
    System.out.println("That's right! you guessed it in " + numberOfTries + " attempt(s)");
    max=Math.max(max, numberOfTries);
    min=Math.min(min, numberOfTries);
    int avg=numberOfTries/round;
    System.out.println("Would you like to play anoter game? (y/n): ");
    String x=keyboard.next();

    [code]
    Here i need to make the guessing game repeat if the user enters a y
    if (x.equalsIgnoreCase(yes)){
    //make the program repeat
    }

    [code/]

    if(x.equalsIgnoreCase(no)){
    System.out.println("Your best score was " + max + " tries");
    System.out.println("Your worst score was " + min + " tries");
    System.out.println("Your average score was " + avg);
    }

    }
    }
    }
  2. In Topic: guessing game

    Posted 9 Oct 2012

    View PostZoquo, on 09 October 2012 - 08:14 PM, said:

    First step: put your code in code tags.




    I have to make a guessing game using java this is what i have so far. Im having a hard time trying to figure out how to keep track of the numbers so i can compare them. For example if the random number is 62 and the user enters 34 it needs to say too low but if the user then enters 32 after 34 it needs to say something like if 34 is too low 34 is also too low. And im also need help when i print out do you want to play again (y/n) i dont know how to make it play the game again. Please help!!!!



    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner keyboard= new Scanner(System.in);
    int secretNumber=(int) (Math.random()* 99 + 1);
    int numberOfTries=0;
    int max=0;
    int min=0;
    boolean win= false;
    String yes= "y";
    String no= "n";

    [code]
    int round=0;
    while(round>=0){
    round++;
    [code/]

    [code]
    while (win == false){
    System.out.println("Guess a number: ");
    int guess=keyboard.nextInt();
    numberOfTries++;
    [code/]

    [code]
    if (guess>100){
    System.out.println("Huh? Your guess should be between 1 and 100");
    }
    else if (guess==secretNumber){
    win= true;
    }
    else if (guess < secretNumber){
    if(guess<=0){
    System.out.println("Huh? Your guess should be between 1 and 100");
    }else
    System.out.println(guess + " is too low");
    }
    else if (guess > secretNumber){
    System.out.println(guess + " is too high");
    }
    }
    [code/]

    [code]
    System.out.println("That's right! you guessed it in " + numberOfTries + " attempt(s)");
    max=Math.max(max, numberOfTries);
    min=Math.min(min, numberOfTries);
    int avg=numberOfTries/round;
    System.out.println("Would you like to play anoter game? (y/n): ");
    String x=keyboard.next();
    [code/]


    [code]
    if (x.equalsIgnoreCase(yes)){
    //make the program repeat
    }


    if(x.equalsIgnoreCase(no)){
    System.out.println("Your best score was " + max + " tries");
    System.out.println("Your worst score was " + min + " tries");
    System.out.println("Your average score was " + avg);
    }[code/]

    }
    }
    }

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner keyboard= new Scanner(System.in);
    int secretNumber=(int) (Math.random()* 99 + 1);
    int numberOfTries=0;
    int max=0;
    int min=0;
    boolean win= false;
    String yes= "y";
    String no= "n";

    int round=0;
    while(round>=0){
    round++;

    while (win == false){
    System.out.println("Guess a number: ");
    int guess=keyboard.nextInt();
    numberOfTries++;



    if (guess>100){
    System.out.println("Huh? Your guess should be between 1 and 100");
    }
    else if (guess==secretNumber){
    win= true;
    }
    else if (guess < secretNumber){
    if(guess<=0){
    System.out.println("Huh? Your guess should be between 1 and 100");
    }else
    System.out.println(guess + " is too low");
    }
    else if (guess > secretNumber){
    System.out.println(guess + " is too high");
    }
    }
    System.out.println("That's right! you guessed it in " + numberOfTries + " attempt(s)");
    max=Math.max(max, numberOfTries);
    min=Math.min(min, numberOfTries);
    int avg=numberOfTries/round;
    System.out.println("Would you like to play anoter game? (y/n): ");
    String x=keyboard.next();

    [code]
    if (x.equalsIgnoreCase(yes)){
    //make the program repeat
    }
    [code/]

    if(x.equalsIgnoreCase(no)){
    System.out.println("Your best score was " + max + " tries");
    System.out.println("Your worst score was " + min + " tries");
    System.out.println("Your average score was " + avg);
    }

    }
    }
    }

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

tjarmon52 hasn't added any friends yet.

Comments

tjarmon52 has no profile comments yet. Why not say hello?