0

I am working on a project where a user enters different types of variables I'm trying to make my project fool proof so I'm trying to prevent a data mismatch. An example of the type of input that I'm asking the user for would be something like this:

int main(){
    int num;
    string name,name2;
    double money
    cout<<"Enter your first name:"<<endl;
    cin>>name;
    cout<<"Enter your last name"<<endl;
    cin>>name2;
    cout<<"Enter a number"<<endl;
    cin>>num;
    cout<<"Enter an amount of money you have"<<endl;
    cin>>money;
}

I'm main worried about the integer and double types of variables. So I'm wondering if there is a kind of exception for data mismatch for both integer and double variable types?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user2340686
  • 97
  • 1
  • 3
  • 11
  • You are missing a semicolon on the 4th line . Also look at this http://stackoverflow.com/questions/2292202/while-loop-with-try-catch-fails-at-bad-cin-input – Evdzhan Mustafa Mar 03 '14 at 23:07
  • A user entering invalid input is not exceptional. So do not use an exception, simply parse the response and say that you are sorry for not understanding it. – Hans Passant Mar 03 '14 at 23:58

0 Answers0