Many thanks for the help with corrections on the basic version of this lab.
What I have is a basic math game - it asks for your name and choice of operation, spits out random numbers, and compares your answer to the actual answer and gives a result. Then, it ends. Now, my teacher wants us to add an option for the player to continue going until they type some option for "quit".
By itself, I was able to add a System.exit that ran properly and ended the game. However, the best way I could figure to continue was to offer another choice point- "would you like to continue? press 6. If you would like to quit, press 7". I tried writing a loop that either invokes the run method or quits, but I keep getting an illegal start of expression error. (Way way at the bottom.)
Am I barking up the wrong tree with trying to invoke this method again? Suggestions?
Just took a quick glance, but that semicolon in line 213 looks troublesome.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Apr 17, 2010
Agreed, thanks =) It got stuck there when I was jockeying some things about... but I took it out, and did a test print on both of those loops. They both run, so I know my loop is valid, I'm just at a loss as to how to create this infinite loop scenario.
Take a look at the Java api for the Integer Class; specifically looking at the parseInt method. Look at what the method does, does it convert an integer to a string? or a string to an integer? then take a look at your program and the if then conditions that evaluate your choice variable.
The ideal way of coding a menu driven program is to use a infinite loop either with while loop or with for loop until the execution stops along with a switch control. for instance
InputReader choice= new InputReader();
int operation= Integer.parseInt(choice);
case 1:System.out.println("Do something here");
case 2:System.out.println("Do something here");
case 6:System.out.println("Bye Bye");
default:System.out.println("Invalid Choice.Please enter the correct Choice.");
Its not rule but this is how its practiced by the programmers as it simplifies your debugging process
Manju Arasula, welcome to Coderanch.
use code tags next time to post any code.
My personal choice in such situation would be a do-while loop since you want the loop to run at least once.
@ the next of the loop, the user is prompted to continue, if he chooses yes, the loop continues again...