Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
I can't figure out how to solve this
Post Body

Background: This was homework. It was due last week but as it is past due I am just asking becuase my failure to get this is bugging me. The prof doesn't include much commenting in his grades, and I haven't put any comments in yet as I usually do that at the end(probably a bad practice).

Basically I don't understand why my efforts to automatically play again are failing. When I run this it just automatically completes. The initial while loop should repeat, but I'm never even prompted to re-evalutate the string "play_again".


/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */

/** * * @author ldl2 */ import java.util.Scanner; import java.util.Random;

public class derp_dada {

public static void main(String[] arg) {

    int guess, actual, guess_number;
    String play_again = "y";

    Scanner scan = new Scanner(System.in);
    Random rand = new Random();

    actual = rand.nextInt(100);
    guess_number = 0;


    while (play_again.equalsIgnoreCase("y")) {


         while (guess_number <= 5) {
            System.out.println("What number do you guess?");
            guess = scan.nextInt();
            if (guess > 100) {
                System.out.println("That isn't valid");
            } else if (guess < 1) {
                System.out.println("That isn't valid");
            } else if (guess < actual) {
                System.out.println("That's too low.");
            } else if (guess > actual) {
                System.out.println("That's too high.");
            } else {
                System.out.println("you got it! and you only made "   guess_number   " guesses");
                guess_number  = 5;
            }
            guess_number  = 1;
            if (guess_number > 5) {
                System.out.println("You are done guessing");
            }

        }

        play_again = (String) scan.nextLine();
        System.out.println("Would you like to play again? ((Y)es/(N)o)");

    }

}

}

Duplicate Posts
2 posts with the exact same title by 1 other authors
View Details
Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
29,182
Link Karma
9,620
Comment Karma
19,547
Profile updated: 7 hours ago
Posts updated: 9 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
8 years ago