Okay, I have a goal right now to make a basic text adventure. To do this, however, I would need/want to have a switch statement that can do the following:
- Check to see if a string has a word SOMEWHERE inside.
- Check to see if a string has two words in any combination somewhere inside.
How would I accomplish this? Could you show me coding for this specific example:
A user is prompted for data. A switch statement checks for “look box” as one case, and “sleep” as another. The program doesn’t care what order any words are in, but does care about the order of the letters.
Please explain everything in detail. I just started coding.
EDIT: Thank you for all the answers. I understand there are better, more complicated, and more useful ways of handling this, but it just isn’t at my level yet.
Here’s another idea:
It uses if/then/else to assess a particular scenario including potential combinations such as input like
"look at the sleep box"and then uses a switch statement to execute accordingly.