Hello, I want to check my program if the user instead of entering a number, if he typed something that is not a number.
so i made this function
void ValidationController::cinError(int *variable){
if(!isdigit(*variable)){
cin.clear();
cin.ignore(256, '\n');
cout <<*variable<<endl;
*variable=0;
cout <<*variable<<endl;
}
}
I call the function as follows:
int more;
cin >>more;
cinError(&more);
So my problem is that every time I give a number, it acts as if I did not. It goes inside if it makes the variable equal to zero. What am I missing here?
source
share