I stumbled upon this infinite loop. I was supposed to check the user's input not to be of any type other than integer and also not to be a negative number. Why am I getting this infinite loop and more importantly how do I impose these restrictions on the input?
#include <iostream>
using namespace std;
int main(){
long long int m, k;
cin >> m >> k;
while (cin.fail() || m < 0 || k < 0){
cin.clear();
cout << "please enter another input";
cin >> m >> k;
}
return 0;
}