-
User Commands
Hi, I wanted to make a simple program, well.....a game actually. Where you can type key commands in such as 'exit' , 'forward', 'drop', etc. So when i am coding this would i have to do different spellings of the same word, ex. 'exit' 'EXIT' 'Exit'. If the user types in 'ExiT' , the program wouldnt recognize this. So how can i account for user errors without having to do all these combos? or is their no other way? :(
-
As input comes in, convert everything to CAPS. There are a variety of methods of doing this. You could use toupper(char) from <ctype> in a loop, though there is probably a better method for strings in the STL.
-
I see.......i guess that could work. Let me try it..... Thanks :p
-
Hmmm.. I was about to post the similar answer with tolower(), but I guess caps works, too. ;)
Basically create a fuction that accepts your string, then converts every element in the string array to lower(or upper)case.
Then you can do something similar to:
Code:
} while (strConvert(userInput) == "EXIT");