I'm creating a simple console application in C++ that contains a while loop that takes two integers as input. But if I enter a character that is not a integer, such as "a", the loop becomes infinite. How do I stop this?
My code is supposed to terminate upon entry of the char value '|' but it takes integers in as input and I'm not sure how to address this problem.
My code so far (trying to end a loop upon input of the char value '|'):
int main()
{
int x = 0;
int y = 0;
char c = {x};
char d = {y};
while (c != '|')
{
cin >> x >> y;
// later I will do stuff with x and y
}
system("pause");
return 0;
}