I am trying to learn the best way to validate data of type float. There are plenty of topics to be found on data validation around but most of the answers do not go indepth enough in explaining how to implement their recommended methods for them to help me. for example: the answer "Get the input as a string, then check if it's a number or not." does not explain the process involved and thus does not help a beginner such as myself.
Right now the only validation code that i have been able to implement is to allow only positive numbers to be input :
1 2 3 4 5 6 7
while (loanAmount < 0)
{
cout << "INVALID DATA" << endl;
cout << "loan amount must not be negative number" << endl;
cout << "try again:" << endl;
input (loanAmount, yearlyRate , monthlyPayment, monthlyRate, desiredYears);
}
If a letter or symbol is input into my program it goes bonkers. What is the best way to avoid this? How can I do that?
Also, I read it is important to clear the stream or something like that after invalid data has been entered. Should I worry about this? what does this mean?