float input;
cin>>input; // if the user type string in input then throw exception
if(!isdigit(input)){
throw "error";
}
But isdigit also throw exception for a numeric value.
How to solve?
float input;
if (cin>>input) {
//all is good
...
} else {
throw "error";
}
is one way to go. Program will take if
path if the input begins with a number and else
path otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With