reset password
Author Message
knagrec2
Posts: 51
Posted 19:50 Sep 15, 2018 |

When writing the code for the menu in the PC selection homework, if the user makes an invalid choice, should the code simply display a message and reload the main menu? Or should it pause on the error message and allow the user to hit a key to go back to the menu?

 

Also should we have exception handling? I think Keenan mentioned this but I wanted to confirm whether or not we need to write exceptions for when the user, say, types a string when selecting the menu option.

 

Edit: I know this is another question, but is it ok to use recursion? I want to call the main menu again after each choice, and recursion seems to be the easiest (only?) way to do that.

Last edited by knagrec2 at 20:21 Sep 15, 2018.
kknaur
Posts: 540
Posted 10:21 Sep 16, 2018 |
knagrec2 wrote:

When writing the code for the menu in the PC selection homework, if the user makes an invalid choice, should the code simply display a message and reload the main menu? Or should it pause on the error message and allow the user to hit a key to go back to the menu?

 

Also should we have exception handling? I think Keenan mentioned this but I wanted to confirm whether or not we need to write exceptions for when the user, say, types a string when selecting the menu option.

 

Edit: I know this is another question, but is it ok to use recursion? I want to call the main menu again after each choice, and recursion seems to be the easiest (only?) way to do that.

You can show an error message and then redisplay the menu. 

No exception handling since this was not introduced yet.

No recursion.  This is a topic for CS2013 and also using recursion for a simple loop-based menu does not make sense.  You would have no way to get out of the recursion and if your program were left to run long enough the successive method calls would fill up the call stack and crash your program.