1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Nested Switch Statement Ambiguous Overload for Operator

Discussion in 'C++' started by norahs63, Oct 8, 2011.

  1. norahs63

    norahs63 New Member

    Joined:
    Sep 30, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I'm pretty sure the ambiguous overload is being caused by having to use the same number to mean different things. I can't find a way to overcome it. It's supposed to be a phone call allocator: Press 1 for Raleigh office, then press 1 for new appointments, 2 for rescheduling an appointment and so on. First compiling error is "Ambiguous overload for Operator 1." Any help would be greatly appreciated. :confused:

    Code:
    #include <iostream>
    using namespace std;
    int main()
    
    {
    
    //Declare Variables
    int menu_choice = 0;
    int next_menu_choice = 0;
    int Raleigh = 1;
    int Durham = 2;
    int ChapelHill = 3;
    
    switch ( menu_choice )
    {
        case 1:
        // Display the area menu
            cout << "Area Menu"
            << "1 = Raleigh"
            << "2 = Durham"
            << "3 = ChapelHill";
    
            cout << "Enter a menu choice: ";
            cin >> next_menu_choice;
            cout << endl;    
            
    switch ( next_menu_choice )
    {
           case '1':
           cout << "Make a new appointment in Raleigh";
           cin >> 1;
           cout << "Make a new appointment in Durham";
           cin >> 2;
           cout << "Make a new appointment in Chapel Hill";
           cin >> 3;
           endl;
           break;
            
            case '2':
            cout << "Reschedule an appointment in Raleigh";
            cin >> 1;
            cout << "Reschedule an appointment in Durham";
            cin >> 2;
            cout << "Reschedule an appointment in Chapel Hill";
            cin >> 3;
             endl;
            break;
            
            case '3':
            cout << "Billing questions in Raleigh";
            cin >> 1;
            cout << "Billing questions in Durham";
            cin >> 2;
            cout << "Billing questions in Chapel Hill";
            cin >> 3;
             endl;
            break;
    
            case '4':
            cout << "Talk to a nurse in Raleigh";
            cin >> 1;
            cout << "Talk to a nurse in Durham";
            cin >> 2;
            cout << "Talk to a nurse in Chapel Hill";
            cin >> 3;
             endl;
            break;
    
    }      //end switch
    
    cout << endl;
    system("pause");
    return 0;
    
    } //end of main function
     
    Last edited by a moderator: Oct 8, 2011
  2. norahs63

    norahs63 New Member

    Joined:
    Sep 30, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I'm going to respond to my own post. This seems to be working well. Any suggestions?

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main( ) {
    
    int location= 0;
    int activity= 0;
    
    cout << "Press 1 for Raleigh office" << endl;
    cout << "Press 2 for Durham office" << endl;
    cout << "Press 3 for Chapel Hill office" << endl;
    
    cout << "Enter Location: "<<endl;
    cin >> location;
    
    cout << "Press 1 for making a new appointment" << endl;
    cout << "Press 2 for rescheduling an appointment" << endl;
    cout << "Press 3 for billing questions" << endl;
    cout << "Press 4 for talking to a nurse" << endl;
    
    cout << "Enter activity: "<<endl;
    cin >> activity;
    
    switch (location) {
    case 1: cout << "Raleigh: "; break;
    case 2: cout << "Durham: "; break;
    case 3: cout << "Chapel Hill: "; break;
    }
    
    switch (activity) {
    case 1: cout << "making a new appointment" << endl; break;
    case 2: cout << "rescheduling an appointment" << endl; break;
    case 3: cout << "billing questions" << endl; break;
    case 4: cout << "talking to a nurse" << endl; break;
    }
    cout << endl;
    system("pause");
    return 0;
    }
     
    Last edited by a moderator: Oct 8, 2011
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Please read the posting guidelines.
     
    norahs63 likes this.

Share This Page