Electrical and Computer Engineering
44 of 45
UAH
CPE 112
Problem Solving Case Study
•void GetYesOrNo( /*out*/ char& response )  // User response char
•
•// Inputs a character from the user and, if necessary,
•// repeatedly prints an error message and inputs another
•// character if the character isn't 'y' or 'n'
•// Postcondition:
•//     response has been input (repeatedly, if necessary, along
•//     with output of an error message)
•//  && response == 'y' or 'n‘
•{
•    do
•    {
•        cin >> response;
•        if (response != 'y' && response != 'n')
•            cout << "Please type y or n: ";
•    } while (response != 'y' && response != 'n');
•}