Having trouble with error trapping with getch

I'm really not sure if it's called error trapping or not since I can't find any tutorials on it but that's the term my teacher taught me. Error trapping is so you can stop the person entering an information you don't want like I'm programming a classic game called Nim where a person picks up 1-3 sticks. But for some reason, even though I think the while loop is right, it won't let me enter a single thing.

The sum of my code is this:

int take;

cout<<"Take: ";
take=getch();
while(take>3||take<1)
take=getch();

It works when I use cin so I don't see what the problem is...
Last edited on
getch() doenst wait for input. So on your second line the programming wont wait, and I think take already got a value so the while-condition will be false.

Run and see or you can understand the following:
1
2
3
4
5
while (true)
{
system("cls");
cout<<getch();
}
Using cin to get user input:
http://www.cplusplus.com/forum/articles/6046/
Last edited on
Topic archived. No new replies allowed.