Hi Everyone.
I have a bit of a problem with validating my input and would really appreciate your help. I will post the code and then explain the problem.
Language: C++
if ((repeat == ';Y';)or(repeat == ';y';))
{
cout<<"\nHow many modules will the student repeat? : ";
cin>>repEnrolled;
cout<<"\nHow many new modules will the student take? : ";
cin>>newEnrolled;
totalTuition=calcFees(newEnrolled, NEW_FEE, repEnrolled, REPEAT_FEE);
}//if loop
else
{
cout<<"\nHow many new modules will the student take? : ";
cin>>newEnrolled;
totalTuition=calcFees(newEnrolled, NEW_FEE);
}//else loop
Ok, now basically, everything works fine when I use valid input, but when I use invalid input e.g. a character or floating point value instead of an integer, the program goes a bit crazy. How can I validate the input as integer values?
Having looked on the web, there were solutions like using cin.good() in a while loop which resulted in an infinite loop.
Let me know what you guys think.
Thanks
Chris Botha
=============================
Far and away the best prize that life has to offer is the chance to work hard at work worth doing.
Theodore Roosevelt