You people have helped me alot...But I got another question for you...

You people have helped me alot...But I got another question for you...

This is a discussion on You people have helped me alot...But I got another question for you... within the C++ Programming forums, part of the General Programming Boards category; Okay. Thanks to my other thread I have started to use cases alot more than before. But I have yet ...

You people have helped me alot...But I got another question for you...

Okay. Thanks to my other thread I have started to use cases alot more than before. But I have yet another question. I am making a text adventure game. And use cases for the commands. But whenever the player enters an invalid command it just closes the program. So my question is. How can I make it so if a player does not use a valid entry it just returns them to the top of the case list or something simaliar? Sorry if this is confusing...But I think you get the idea. I tried else case but it wouldn't work...maybe I just didn't use it right or something. Any help here?

Sorry for all these questions but how do I make it so if they don't enter a valid entry it just starts the case thing over again? Should I just use the case inside the default case? Sorry if that didn't make much sense...I don't explain things very well.

Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Nothing but a valid command will get through the DO...WHILE statement and, anything else input will simply clear the screen back to the prompt again.

Enmeduranki supplies an error message which is not a bad idea from a 'user-friendly' standpoint, but I opted to exclude this feature to avoid cluttering the screen with text while the player learns to type.

XSquared's idea is very good (which is why I included the methodology in my example ) but doesn't show that the default case element must re-prompt the player or else the execution will result in an infinite loop. (Very minor issue, but, once again, you could end up with a fair amount of useless text on the screen.)

It's possible - probable ? - that someone will suggest (correctly) that DO...WHILE statements aren't the best idea. True enough, but in this case, that rule-of-thumb can be discounted since the player must be prompted, at least, once here.

P.S. The 'default' case element in the switch statement (with the break; included) isn't really necessary, but is still good practice.