Chapter 8 Exercises

  1. Replace the code in the body of the main function with a call to a function named getResponse. Put the original code in the function.
    #include <iostream>
    
    using namespace std;
    
    int main(){
        char response = '!'; // initialized to an invalid response
    
        do{
            cout << "Please type y or n: ";
            cin >> response;
        } while( (response != 'y') && (response != 'n'));
    
        cout << "You entered " << response << endl;
    
        return 0;
    }
    
    Your results should at least have the following code:
    #include <iostream>
    
    using namespace std;
    
    int main(){
        char response = '!'; // initialized to an invalid response
    
        // To-Do: Add call to getResponse()
    
        cout << "You entered " << response << endl;
    
        return 0;
    }