Validating Switch Statement.

Hi

I wanted to know if there is a way of validating the input on a switch statement?
One of the cases is the letter 'l' but if I input a word that contains the letter it still runs which I don't want it to. Is there a way of checking?

If anyone can help, I would really appreciate it.

Thanks

 
  
Last edited on
Could you provide a code example of your problem?
That's the loop and the switch statement i am trying to use. If i type a word that contains any of the letters it still runs, which i don't want it to.

Thanks
You haven't show the definition of move. From your usage, I presume it is a char, but that is not clear.

cin of a char will remove exactly one character from the input buffer. That doesn't prevent the user from entering additional characters. If you want to ignore additional characters, you can do the following after line 11.
1
2
3
 
  cin.ignore (1024);
  cin.clear ();

http://www.cplusplus.com/reference/istream/istream/ignore/
http://www.cplusplus.com/reference/ios/ios/clear/

BTW, if the user enters an invalid character, you're going to display the message at line 52, then fall thru to the call to moves() at line 54 as if the input was valid. row,col,count,progress,remove may not be valid.
Last edited on
AbstractionAnon you bloody legend!

Thanks for your help i appreciate it.
Last edited on
Topic archived. No new replies allowed.