Validating char input

Hey, I'm trying to validate a char input so that it only accepts 'g','s' or 'e'.

1
2
3
4
while(x != 'e' && x != 's' && x != 'g')
{

}


But if I input more than one char on the line starting with g/s/e it will still validate, I'm clearing the buffer inside the while but it still reads the first char.

I read http://www.cplusplus.com/forum/articles/6046/ but i was just wondering if there was a simpler way to do it because I dont think our Prof has taught us that.
Last edited on
Topic archived. No new replies allowed.