I have looked everywhere but I can't seem to find and implement an input validation that only takes in integers, I have my code running perfectly fine but my only problem is that since ive added my validation code, it requires the user to enter twice before it accepts the second input, all I want is for the user to only have to enter in once with good validation so the program recognizes its not a int and displays the appropriate message, id be very appreciative of any help!
Here's my code:
cout<<"Please enter your first value: \n";
cin>>a;
//Error checker to check if input is a number
while(!(cin >> a))
{
cin.clear();
std::cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Invalid input. Please Try again: "<<endl;
}
cin>>a
line? – Joachim Pileborg Apr 19 at 23:52