Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to check that is number or not

How to check that is number or not

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
3 Posts 3 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KARFER
    wrote on last edited by
    #1

    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)

    J D 2 Replies Last reply
    0
    • K 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)

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      goto Begin; And You think you get away with that? You can make this a

      while(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.

      1 Reply Last reply
      0
      • K 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)

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        The variable no needs to be changed to a string or a char[]. 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups