infinate while loop

hey, im sure this is a really simple problem but im baffled as to why i get an infinate loop if a character and not a number is inputed using this code:

do {
cout << "please enter either 1 or 2";
cin >> c1;

}

while ((c1 != 1) && (c1 != 2));

thx in advance
I'm assuming c1 is an int...anyway, it's more of a bug with cin >> then with you. Read http://www.cplusplus.com/forum/articles/6046/ for how to get around it.
I would expect c1 to be a char, and compare it against the characters '1' and '2'. Note that '1' has an ASCII value of 49, not 1. Look up an ASCII chart for more information about chars and their integral representation.
Topic archived. No new replies allowed.