You could just use a char instead.
When x is an int, cin>>x will only read an int from the input. If there is a char there, it'll do nothing (leaving the char there) and next time through the loop, the same char will still be there.... infinite loop.Code:char x; while (x != '6') ....
I'd just use a char, and convert it back to an integer at a later point if I need to.