hi all,
can anyone enlighten me on this? i need a validation function that must only take in 'numbers' and '.'
for example the amount i want to enter is 9.90
but what my code is taking in is all other punctuation also. like !:"+()
my code is as follows:
bool valid=true;
if(income == "0")
{
cout << "\n";
cout << "Invalid income entered." << endl;
cout << "Income should not be 0." << endl;
cout << "\n";
valid=false;
}
else
{
for(int j=0; j<income.length(); j++)
{
if(!isdigit(income[j]) && !ispunct(income[j]))
{
cout << "\n";
cout << "Invalid income entered." << endl;
cout << "Income should not contain alphabets/characters." << endl;
cout << "\n";
valid=false;
}
}
any help/comments are welcome. Thanks alot!!
sorry forget to add the main body
do
{
cout << "Enter income amount or other cash inflows values:" << endl;
cout << "$";
cin >> income;
valid = incomeValid(income); // Income validation
}
while(!valid);
thanks!