Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Return statement for beginning of a switch?

I'm in an absolute standstill right now and have no idea where to go from. I'm in a very entry level "programming" class and I just need a bit of help.

I've got the program all down but I just need help after completing the "case" to go back to the start of the problem. There are 5 different cases and case 6 breaks the program and ends it. I just don't know what kind of statement to use to make it go to the very top of the program.

Basically from looking at that after completing the 5 problems in which ever case I need it to prompt the user the first dialogue again the "Welcome to..." one.

"updated" code: http://pastebin.com/1Hb0hxGt

Still having problems making it go back to the first statement
You could wrap all of your code in a while statement.
pseudo-code example:
Code
while (!inputString.equals("exit")) {...}
(Oct 9, 2015 11:13 AM)MrMysteri0us Wrote:  You could wrap all of your code in a while statement.

Just make it while(true)?

I'm not like to keen on all of these terms yet.

Would it still break if 6 was entered?
Yes, you could do that as well, it's not good code (to use while(true)) after all, but it's probably good enough for your class :)
No it wouldn't. You have to use "return;" instead of "break;" in case 6.
(Oct 9, 2015 11:18 AM)MrMysteri0us Wrote:  Yes, you could do that as well, it's not good code (to use while(true)) after all, but it's probably good enough for your class :)
No it wouldn't. You have to use "return;" instead of "break;" in case 6.


Alright sweet thanks a bunch I knew it was something simple as that, not extremely worried about making the whole thing while(true)... I don't think he'll care.

I just now need to figure up how to add up all the correct answers (which it should be by using 'correct') and then divide them by the total number of questions if they decide to use another case which would be totalQ if I have it all set up right once the user selects 6.

edit: stuck again, not sure why but after the 5 problems are complete the whole program just stops and it prints out what is in case 6.


"updated" code:
http://pastebin.com/1Hb0hxGt
(Oct 9, 2015 11:34 AM)Woe Is Me Wrote:  Alright sweet thanks a bunch I knew it was something simple as that, not extremely worried about making the whole thing while(true)... I don't think he'll care.

I just now need to figure up how to add up all the correct answers (which it should be by using 'correct') and then divide them by the total number of questions if they decide to use another case which would be totalQ if I have it all set up right once the user selects 6.

edit: stuck again, not sure why but after the 5 problems are complete the whole program just stops and it prints out what is in case 6.


"updated" code:
http://pastebin.com/1Hb0hxGt

if your trying to make it loop around once your done, call main from inside itself after the default.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by OBAMASELFApr 23, 2019 12:42 AM 4 245 Apr 23, 2019 12:42 AM
Last Post: Joseph Stalin
[Java] by blackcoder00Mar 11, 2019 07:20 AM 5 245 Mar 11, 2019 07:20 AM
Last Post: blackcoder00
[Java] by KusoApr 30, 2017 07:23 AM 11 414 Apr 30, 2017 07:23 AM
Last Post: Owl