Thanks to the break
overload, which means βend of switch caseβ and βexit loopβ, this is one of those unusual times when goto
comes up.
do { again: 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?"; goto again; } cout << "Do you want to continue? (Y/N)" << endl; cin >> stopApp; } while(toupper(stopApp) == 'Y');
FYI "man" and "woman" are not the only options for gender . Depending on your larger goals, I would recommend that you do not ask this question at all, allow the user to provide an arbitrary phrase in response, or, if this is a medical application in which the biological sex is factual important information, ask instead (and again allow the provision of an arbitrary phrase , because it is also not binary).
zwol source share