title: Can a c++ program have an switch statement inside an if/else statement
body: <p>I am trying to do a switch statement inside an if/else statement. It does not work. I am not sure if it is because the reserved word "break" that i use inside the switch statement takes me out of the function. Please help!!!</p>
  
  <pre><code>    /*  Date : March 3, 2015
      Date Due : March 23, 2015
      Program Name: Hospital Calculator
      Description: This program will ask the user to enter several information 
      related to his/her room floor measurements. After that, it will generate 
      a bill that will tell the customer the price for the carpet job.
      */
  
    #include &lt;iostream&gt;
    #include &lt;iomanip&gt;
    #include &lt;string&gt;
    #include &lt;cmath&gt;
    #include &lt;cctype&gt;
  
    //Constants
                // Room Rates
    const float SINGLE_ROOM    = 525.00,
                DOUBLE_ROOM    = 325.00,
                WARD           = 550.00,
                //Phone Access Rates
                SHARED_LINE    = 2.95,
                DEDICATED_LINE = 5.95,
                //Television Rates
                BASIC_CHANNELS = 2.95,
                CABLE_CHANNELS = 5.95;
  
    using namespace std;
  
      //Prototypes
    void getdata(string &amp;, int &amp;);
    float get_room ( int,  string &amp;);
    float get_phone(int days, string &amp;);  
  
  
    int main()
    {
       string name,
              room_type,
              phone_type,
              tv_type;
  
       int   days;
  
      float room_charges,
            phone_charges,
            tv_charges;
  
      //The ones below are subfuntions calls that devide each section    
  
    //Input section (call)
      getdata(name,days);
    //room_charges = 
    //room_charges = get_room(days,room_type);
    phone_charges = get_phone(days, phone_type);
    cout &lt;&lt; phone_charges &lt;&lt; endl;
    cout &lt;&lt; phone_type &lt;&lt; endl;
  
    /*tv_charges = get_tv(days, tv_type);
    print(name, days, room_charges, phone_charges, tv_charges);
    */
  
      cin.get();
      cin.ignore();
      return 0;
    }
  
    // Input Section
    //This function takes the information needed from the user
    void getdata(string &amp; name, int &amp; days)
    {
      string symbol;
  
      symbol.assign (50, '*');
      cout &lt;&lt; symbol&lt;&lt; endl;
      cout &lt;&lt; right &lt;&lt; setw(22) &lt;&lt; "\tCustomer's Name\t\t\t: ";
      getline (cin,name);
      cout &lt;&lt; right &lt;&lt; setw(22) &lt;&lt; "\tNumber of days in the hospital\t\t: ";
      cin &gt;&gt; days;
      cout &lt;&lt; symbol &lt;&lt; endl; 
      cin.ignore();
    }
  
    float get_room ( int days, string &amp; room_type)  
    {
        string choice;
        char   ch;
        float  room_charges;
        cout &lt;&lt; "\n\n\t\t\tRoom Used\n";
        cout &lt;&lt;     "\t\t\t________\n\n";
        cout &lt;&lt; fixed &lt;&lt; setprecision (2);
        cout &lt;&lt; "\t1- Single room-One bed \t"&lt;&lt; SINGLE_ROOM &lt;&lt;"\n\n";
        cout &lt;&lt; "\t2- Double room-Two beds\t"&lt;&lt; DOUBLE_ROOM &lt;&lt;"\n\n";
        cout &lt;&lt; "\t3- Ward                \t"&lt;&lt; WARD &lt;&lt;"\n\n";
        cout &lt;&lt; "\t   Enter Choice 1, 2, or 3 : ";
        getline(cin, choice); 
        cin.ignore();
        ch = toupper(choice[0]);
  
        if (ch == '1' or ch == 'S')
           { 
              room_charges = SINGLE_ROOM * days;
              room_type    = "in a Single Room";
           }
  
        else if (ch == '2' or ch == 'D')
          { 
              room_charges = DOUBLE_ROOM * days;
              room_type    = "in a Double Room";
           }
  
        else if (ch == '3' or ch == 'W')
          {
              room_charges = WARD * days;
              room_type    = "in a Ward";
          }
  
  
  
        return room_charges;
  
    }
  
     float get_phone(int days, string &amp; phone_type)
  
    {  
        string prompt,
               choice;
        char   pr, ch;
        float  phone_charges;
        cout &lt;&lt; "Would you like Phone Access (Y/N): ";
        cin &gt;&gt; prompt;
        pr = toupper(prompt[0]);
  
        if (pr == 'Y') 
        {
            cout &lt;&lt; "\n\n\t\t\tPhone Access\n";
            cout &lt;&lt;     "\t\t\t________\n\n";
            cout &lt;&lt; "\t1- Shared   \t" &lt;&lt; SHARED_LINE &lt;&lt;"\n\n";
            cout &lt;&lt; "\t2- Dedicated\t"&lt;&lt; DEDICATED_LINE &lt;&lt;"\n\n";
            cout &lt;&lt; "\t   Enter Choice 1 or 2: ";
            getline(cin, choice); 
  
            ch = toupper(choice[0]);
  
            if (ch == '1' or ch == 'S')
             { 
                 phone_charges = (SHARED_LINE * days);
                 phone_type    = "(Shared)";
  
             else if (ch == '2' or ch == 'D')     
               case '2':
               case 'D':        
                {
                 phone_charges = (DEDICATED_LINE * days);
                 phone_type    = "(Cable)";
                 break;
                }  
  
  
             }
  
  
        }    
  
          else if (pr == 'N')
          {
            phone_charges = 0.00;
            phone_type = "None";
          }
  
           cin.ignore();
            return phone_charges;  
  
       }
  </code></pre>