KMMATH
Feb 22nd, 2002, 02:44 PM
I am asking the user to enter a number and want to display an error message and ask again if the user incorrectly enters an alpha character.
These work with the correct input (numeric), but won't work with the wrong input (alpha)
Please help
void get_loan_amount(double& lamount)
{
using namespace std;
do
{
cout << "Please enter the loan amount: $";
cin >> lamount;
} while (isalpha(lamount));
return;
}
OR
void get_loan_amount(double& lamount)
{
using namespace std;
double amount;
do
{
cout << "Please enter the loan amount: $";
cin >> amount;
lamount = amount;
} while (!isdigit(amount));
return;
}
These work with the correct input (numeric), but won't work with the wrong input (alpha)
Please help
void get_loan_amount(double& lamount)
{
using namespace std;
do
{
cout << "Please enter the loan amount: $";
cin >> lamount;
} while (isalpha(lamount));
return;
}
OR
void get_loan_amount(double& lamount)
{
using namespace std;
double amount;
do
{
cout << "Please enter the loan amount: $";
cin >> amount;
lamount = amount;
} while (!isdigit(amount));
return;
}