I want the program to loop until the input is valid (x is an int, and x>0), but my program accepts the input when I give it 1,1 and loops infinitely when I give a string to it, repeating "Wrong input!".
#include <iostream>
using namespace std;
int main()
{
bool fail;
int x;
do{
cin >> x;
fail=(cin.fail() || x<=0);
if (fail){
cout << "Wrong input!" <<endl;
cin.clear();
};
}while(fail);
return 0;
}