hawaiian1975
Programmer
I am working on a currency program, however when someone inserts a letter, my program goes crazy. Here is the code where I do error checking, however I can never get it to work right.
if(choice < '6'){
// Get amount to be converted
cout << "Enter amount to convert: ";
cin >> usAmount;
// Error checking for anything not numerical
if(usAmount >= 0 && usAmount <= 10000){
// Perform conversion
convertAmount = usAmount * curRate;
// Conversion output
// The following line formats the output to show a dollar format
cout << setiosflags(ios::showpoint | ios::fixed) << setprecision(2);
cout << "Rate as of today: " << usAmount << " of " << curName << " is ";
cout << convertAmount << " US Dollar(s)." << endl << endl;
}else{
cout << "\tError: Invalid Choice." << endl << endl;
bCont = false; // The loop will end upon invalid input
exit(1);
}
}else{
cout << "\tError: Invalid Choice." << endl << endl;
}
} while(bCont);
if(choice < '6'){
// Get amount to be converted
cout << "Enter amount to convert: ";
cin >> usAmount;
// Error checking for anything not numerical
if(usAmount >= 0 && usAmount <= 10000){
// Perform conversion
convertAmount = usAmount * curRate;
// Conversion output
// The following line formats the output to show a dollar format
cout << setiosflags(ios::showpoint | ios::fixed) << setprecision(2);
cout << "Rate as of today: " << usAmount << " of " << curName << " is ";
cout << convertAmount << " US Dollar(s)." << endl << endl;
}else{
cout << "\tError: Invalid Choice." << endl << endl;
bCont = false; // The loop will end upon invalid input
exit(1);
}
}else{
cout << "\tError: Invalid Choice." << endl << endl;
}
} while(bCont);