How to check that is number or not
-
Hello all i have problem that when i'm input a character in emp_no field the program end or exit i want that when i input number the program accept it and when i input character display me message that is wrong input and return to input number again i used isdigit function but i want to return input again if the input not number and Thank's For All
class EMPLOYEE { private: int emp_no; char emp_name[30]; int age; int selary; int taxt; public: //EMPLOYEE(void); void set_emp_no(int no) { emp_no=no; } int get_emp_no() { return emp_no; } void set_emp_name() { cin>>emp_name; } void get_emp_name() { cout<>no; if (isdigit (no)) set_emp_no(no); else { if (isalpha (no)) cout <<"error man"; } goto Begin; cout <<"\nEnter Employee Name:"; set_emp_name(); }
To Be Or Not To Be (KARFER)
-
Hello all i have problem that when i'm input a character in emp_no field the program end or exit i want that when i input number the program accept it and when i input character display me message that is wrong input and return to input number again i used isdigit function but i want to return input again if the input not number and Thank's For All
class EMPLOYEE { private: int emp_no; char emp_name[30]; int age; int selary; int taxt; public: //EMPLOYEE(void); void set_emp_no(int no) { emp_no=no; } int get_emp_no() { return emp_no; } void set_emp_name() { cin>>emp_name; } void get_emp_name() { cout<>no; if (isdigit (no)) set_emp_no(no); else { if (isalpha (no)) cout <<"error man"; } goto Begin; cout <<"\nEnter Employee Name:"; set_emp_name(); }
To Be Or Not To Be (KARFER)
goto Begin;
And You think you get away with that? You can make this awhile(1) {
...
}loop.
if( isdigit( no)) could be changed to
if(!
isdigit( no)) {
...complain about error here...
}and the
isalpha
could subsequently be dropped.
Failure is not an option - it's built right in.
-
Hello all i have problem that when i'm input a character in emp_no field the program end or exit i want that when i input number the program accept it and when i input character display me message that is wrong input and return to input number again i used isdigit function but i want to return input again if the input not number and Thank's For All
class EMPLOYEE { private: int emp_no; char emp_name[30]; int age; int selary; int taxt; public: //EMPLOYEE(void); void set_emp_no(int no) { emp_no=no; } int get_emp_no() { return emp_no; } void set_emp_name() { cin>>emp_name; } void get_emp_name() { cout<>no; if (isdigit (no)) set_emp_no(no); else { if (isalpha (no)) cout <<"error man"; } goto Begin; cout <<"\nEnter Employee Name:"; set_emp_name(); }
To Be Or Not To Be (KARFER)
The variable no needs to be changed to a
string
or achar[]
. Then you can loop through each character to determine if it is a digit or not.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne