checking for TYPE INT

Discussion in 'C++' started by JC, Nov 12, 2003.

  1. JC

    JC Guest

    Hello,

    I was wondering if there is a way I can check for the TYPE of answer I
    receive from a user

    For example I'm writing a program that requires the user to enter a integer
    (TYPE INT)
    if someone enters a type CHAR, or any other type other than INT, I want to
    display a message...

    example code.

    int num,

    cout <<"\n please enter a number to add to the list";
    cin >> num; // I want to check here to make sure they enter a INT...
    I do not want to continue with the program is not INT.

    Thank you for all of your help!
    JC
     
    JC, Nov 12, 2003
    #1
    1. Advertising

  2. JC

    Artie Gold Guest

    JC wrote:
    > Hello,
    >
    > I was wondering if there is a way I can check for the TYPE of answer I
    > receive from a user
    >
    > For example I'm writing a program that requires the user to enter a integer
    > (TYPE INT)
    > if someone enters a type CHAR, or any other type other than INT, I want to
    > display a message...
    >
    > example code.
    >
    > int num,
    >
    > cout <<"\n please enter a number to add to the list";
    > cin >> num; // I want to check here to make sure they enter a INT...
    > I do not want to continue with the program is not INT.
    >
    > Thank you for all of your help!


    See:

    http://www.parashift.com/c -faq-lite/input-output.html#faq-15.3

    (In fact, reading the whole section would be a good idea. Come to
    think of it, you *really* should have read the FAQ *before* posting
    a question.)

    HTH,
    --ag



    --
    Artie Gold -- Austin, Texas
    Oh, for the good old days of regular old SPAM.
     
    Artie Gold, Nov 12, 2003
    #2
    1. Advertising

  3. JC

    JocelynBruno Guest

    I just encountered the very same situation and am greatful at your response to
    JC's question on 'Checking for int'. Your solution is much easier than the
    approach I was about to take. This newsgroup is ok! I'll be reading the FAQ's
    every chance I get!

    Your guidance is appreciated!

    JB
     
    JocelynBruno, Nov 12, 2003
    #3
  4. JC

    JC Guest

    Thank you Artie for the solution.
    I'll give this a try

    "Artie Gold" <> wrote in message
    news:...
    > JC wrote:
    > > Hello,
    > >
    > > I was wondering if there is a way I can check for the TYPE of answer I
    > > receive from a user
    > >
    > > For example I'm writing a program that requires the user to enter a

    integer
    > > (TYPE INT)
    > > if someone enters a type CHAR, or any other type other than INT, I want

    to
    > > display a message...
    > >
    > > example code.
    > >
    > > int num,
    > >
    > > cout <<"\n please enter a number to add to the list";
    > > cin >> num; // I want to check here to make sure they enter a

    INT...
    > > I do not want to continue with the program is not INT.
    > >
    > > Thank you for all of your help!

    >
    > See:
    >
    > http://www.parashift.com/c -faq-lite/input-output.html#faq-15.3
    >
    > (In fact, reading the whole section would be a good idea. Come to
    > think of it, you *really* should have read the FAQ *before* posting
    > a question.)
    >
    > HTH,
    > --ag
    >
    >
    >
    > --
    > Artie Gold -- Austin, Texas
    > Oh, for the good old days of regular old SPAM.
    >
     
    JC, Nov 12, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,251
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,709
    Old Wolf
    Jan 20, 2004
  3. arun
    Replies:
    8
    Views:
    481
    Dave Thompson
    Jul 31, 2006
  4. aling
    Replies:
    8
    Views:
    1,031
    Jim Langston
    Oct 20, 2005
  5. Replies:
    9
    Views:
    464
    James Kanze
    Apr 17, 2007
Loading...

Share This Page