Hi guys . I'm new to c++ . My last objective is to check if the input has a decimal value . If it has, then it will not be accepted by the program and it will undergo the loop of the wrong input .
(I'll just show here the function part where my concern shows)
void widrawMoney(double& newbalance)
{
int thd=1000, fhnd=500, thnd=200, ohnd= 100 ;
int wnum, ctr;
double test;
cout<<" Enter amount to Withdraw: ";
cin>>wnum;
//this is the code for the breakdown of money inputted
newbalance= newbalance - wnum;
}
else if ((wnum<=500.00)||(wnum>=5000.00)) -----> i need another condition to test if the input has a decimal so that the input with decimal will proceed to this condition/loop
{
while ((wnum<500.00)||(wnum>5000.00))// loop for the validation of the range of amount to be inputted
{
cout<<" Amount should be 500 - 5000 only "<<endl;
cout<<" Enter amount to Withdraw: ";
cin>>wnum;
Get the input as a string. Check that is is composed only of digits and a single decimal point (and presumably that there are two digits only after the decimal point). If so, convert to a double and continue.
The input should be int because there is part where the amount(input) is broken down to money/currency and my professor requires me. Is there any way to check if it has decimal value to insert in the condition ? And one more thing. The input is just a test to know if it has decimal value, then if it is, it will go to the loop for the re-entering of a correct amount of input
If you take the input from the user and store it in an int, I guarantee that it will not have a decimal point in it when you check that stored int value.