Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to show a message on mismatch of data type?

Reply
Thread Tools

How to show a message on mismatch of data type?

 
 
anchitgood@gmail.com
Guest
Posts: n/a
 
      07-11-2008
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?
 
Reply With Quote
 
 
 
 
Stefan Naewe
Guest
Posts: n/a
 
      07-11-2008
On 7/11/2008 1:15 PM, http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
amirkam1@yahoo.com
Guest
Posts: n/a
 
      07-11-2008
On 11 Jul, 19:15, (E-Mail Removed) 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?


Take a look at
http://forums.msdn.microsoft.com/de-...-5d134cce6834/

Amir
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: When running Ant on command line, how to not-show its WARNING messages and only show ERROR message? Roedy Green Java 5 12-13-2011 05:49 PM
Re: When running Ant on command line, how to not-show its WARNINGmessages and only show ERROR message? Lew Java 0 12-10-2011 01:46 AM
Re: When running Ant on command line, how to not-show its WARNING messages and only show ERROR message? John B. Matthews Java 0 12-09-2011 05:19 PM
System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. psychomad ASP .Net 2 04-10-2007 07:31 PM



Advertisments