Wednesday, 18 September 2013

repeat do while loop if switch statement reaches default

repeat do while loop if switch statement reaches default

I have a do while loop asking for user input. Inside this do while loop I
have a switch statement. How can I make it so that if the default value is
met repeat the loop asking for the users gender again?
do
{
cout << "What is your weight?" << endl;
cin >> weight;
cout << "What is your height?" << endl;
cin >> height;
cout << "What is your age?" << endl;
cin >> age;
cout << "What is your gender?" << endl;
cin >> gender;
switch (gender)
{
case 'M':
case 'm':
cout << endl << Male(weight, height, age);
break;
case 'F':
case 'f':
cout << endl << Female(weight, height, age);
break;
default:
cout << "What is your gender?";
}
cout << "Do you want to continue? (Y/N)" << endl;
cin >> stopApp;
} while(toupper(stopApp) == 'Y');

No comments:

Post a Comment