How to show a message on mismatch of data type?

A

anchitgood

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?
 
S

Stefan Naewe

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top