while (GetContinue()) { ... }
return_type identifier([parameter list]);
for the function prototype
return_type identifier([parameter list]) { ... return expression; }
expression
must be of type return_type
return;
will suffice.
parameter_list
can be empty or void
.
GetContinue: Input: no input from main Output: returns a bool (yes continue -> true, no don't continue -> false) While we don't have a response of yes or no Print the prompt read in the response convert the response to lower case return the response
bool GetContinue() { string answer; while (answer!= "yes" and answer != "no") { cout << "Do you wish to encrypt a message (yes/no)? "; getline(cin, answer); cout << endl; answer= ToLower(answer); } return answer == "yes"; }
int main() { while (GetContinue()) { cout << "\tProcessing a code" << endl; } return 0; }