How to show a message on mismatch of data type?

Discussion in 'C++' started by anchitgood@gmail.com, Jul 11, 2008.

  1. Guest

    Hi,
    Please consider the following code:

    {
    int model; //stores model of a car
    cout<<"Enter model of the car :";
    cin>>model;
    }

    Now if the user enters a non - int value (say char), then how can i
    show a message "Invalid Entry" instead the program gets terminated?
     
    , Jul 11, 2008
    #1
    1. Advertising

  2. Stefan Naewe Guest

    On 7/11/2008 1:15 PM, wrote:
    > Hi,
    > Please consider the following code:
    >
    > {
    > int model; //stores model of a car
    > cout<<"Enter model of the car :";
    > cin>>model;
    > }
    >
    > Now if the user enters a non - int value (say char), then how can i
    > show a message "Invalid Entry" instead the program gets terminated?


    if(cin>>model )
    handle_correct_input();
    else
    handle_invalid_input();


    HTH

    S.
    --
    Stefan Naewe stefan dot naewe at atlas-elektronik dot com
    Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
    Plain text mails only, please http://www.expita.com/nomime.html
     
    Stefan Naewe, Jul 11, 2008
    #2
    1. Advertising

  3. Guest

    , Jul 11, 2008
    #3
    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. data type mismatch error

    , Aug 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    644
    Karl Seguin
    Aug 10, 2005
  2. psychomad
    Replies:
    2
    Views:
    5,266
    Alexey Smirnov
    Apr 10, 2007
  3. Bobby Edward
    Replies:
    1
    Views:
    4,499
    Kevin Spencer
    Mar 5, 2008
  4. Jack
    Replies:
    7
    Views:
    218
  5. programmingzeal
    Replies:
    0
    Views:
    1,152
    programmingzeal
    May 6, 2012
Loading...

Share This Page