bool getDouble ( double & value, const string & prompt);
int main()
{
char userSelection;
do
{
cin >> userSelection;
if (userSelection == '1')
{
double radius;
if (getDouble (radius, "Please enter a value: "))
{
cout << "good";
}
else
{
cout << "bad";
}
}
}
while (userSelection != 'Q');
cout << "Thank you for using my program." << endl;
exit (EXIT_SUCCESS);
}
bool getDouble (double & value, const string & prompt)
{
cout << prompt;
if (cin >> value)
{
returntrue;
}
returnfalse;
}
I stripped the majority of code out, there was a menu and such, but I took it all away so you could see the main issue. My problem is, that, if the user enters '1', and then an invalid value, such as 't', it loops instead of ending and asking for the menu selection again. I thought since I put if (getDouble (radius, "Please enter a value: ")) it would just output bad, but it outputs bad forever basically. Is there anything, in my basic knowledge that I'm overlooking? I was thinking something in the while statement, but I'm not sure what. Thanks.