the sample code that i made is to accept only integer number and will display an error message that will tell user that only integer is allowed. the problem is that when the user input multiple characters the error messages will also display the same amount of user inputs. how do i limit the display error message to one if the user input multiple characters?
this is sample output im having trouble with.
Input Integer: ab
Not a Valid Input! Please Enter a Number:Not a Valid Input! Please Enter a Number:
this is the code:
#include<iostream>
int number_checker();
using namespace std;
int main(){
int num;
cout<<"Input Integer: ";
num=number_checker();
cout<<"your input is : " <<num;
}
int number_checker() //check if input is integer
{
int n;
cin>>n;
while(cin.fail())
{
cin.clear();
cin.ignore();
cout<<"Not a Valid Input! Please Enter a Number:";
cin>>n;
}
return n;
}