Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how throw exception when user store string in float variable?

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?

like image 243
shah Avatar asked Jun 11 '15 06:06

shah


1 Answers

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.

like image 114
Mohit Jain Avatar answered Nov 20 '22 12:11

Mohit Jain