(Last Revision -- 03/12/00)
if-Statement and else-Statment with Nesting
#include <iostream.h>
#include <string>
/* illustrates use of nested if-else statements */
int main()
{
    string response;
    
    cout << endl ;
    cout << "Which do prefer, dogs or cats?[dogs/cats]: ";
    cin >> response;
    if ("dogs" == response)
    {
        cout << endl ;
        cout << "Do you like big dogs?[yes/no]: " ;
        cin >> response;
        if ("yes" == response)
        { 
           cout << endl ;
           cout << "Big dogs can be a real pleasure." << endl ;
           cout << "I recommend you get a mastiff." << endl ;
           cout << endl ;
        }
        else /* Here we are assuming the response was "no" */
        {
           cout << endl ;
           cout << "A small pet is often a wise choice." << endl ;
           cout << "You ought to get a chihuahua." << endl ;
           cout << endl ;
        }
    } /* end of outer if-statement */
    else  /* Here we are assuming the response was "cats" */
    {
        cout << endl ;
        cout << "Do you like long-haired cats?[yes/no]: " ;
        cin >> response;
        if ("yes" == response)
        { 
           cout << endl ;
           cout << "Long-hairs sure are beautiful." << endl ;
           cout << "I recommend you get a Persian." << endl ;
           cout << endl ;
        }
        else /* Here we are assuming the response was "no" */
        {
           cout << endl ;
           cout << "A short-hair is more practical." << endl ;
           cout << "How about a tabby cat?" << endl ;
           cout << endl ;
        }
    } /* end of outer else-statement */
    return 0;
}