Working on a simple dice rolling game using programmer defined methods in Java. Since I know the program needs to run at least once and then ask if the player wants to go again, I elected to use a do/while loop. I've never had to use one before, but I believe I set it up right.
My code is as follows, excluding the body of my main method contained within the loop, as well as the programmer defined methods.
do {
// main METHOD BODY ..
String proceed = ui.nextLine();
System.out.print("Would you like to play again (yes/no)? ");
} while (proceed.charAt(0) == 'Y' || proceed.charAt(0) == 'y');
What I get from the Eclipse IDE at this point is "proceed cannot be resolved."
Any ideas as to what's going on?
proceed isn't in scope at the time it is being dereferenced in the while loop. Move the declaration of the proceed variable outside of the do.
String proceed;
do{
main METHOD BODY
proceed = ui.nextLine();
System.out.print("Would you like to play again (yes/no)? ");
} while (proceed.charAt(0) == 'Y' || proceed.charAt(0) == 'y');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With