Thread: nested switch statements error

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    9

    nested switch statements error

    I'm getting the control cannot fall through to another case error and I'm not seeing how to fix it. What am I missing?
    Code:
      public void agouti_color_steel()
            {
                switch (offspring[4])
                {
                    case 1:
                     if ((charlie == true) & (dilute == false))
                        {
                            color = "Charlie Steel Chestnut";
                            gtype = "EnEnA-B-C-D-E/s-VV";
                            colorname();
                        }
    
                        else if ((broken == true) & (dilute == false))
                        {
                            color = "Broken Steel Chestnut";
                            gtype = "EnenA-B-C-D-E/s-VV";
                            colorname();
                        }
    
                        else if (dilute == false)
                        {
                            color = "Steel Chestnut";
                            gtype = "enenA-B-C-D-E/s-VV";
                            colorname();
                        }
    
                                switch (offspring[8])
                     {
                                   case 1:
                                        break;
                           case 2:
                             if (charlie == true)
                             {
                                 color = "Charlie Steel Opal";
                                 gtype = "EnEnA-B-C-ddE/s-VV";
                                 colorname();
                             }
    
                             else if (broken == true)
                             {
                                 color = "Broken Steel Opal";
                                 gtype = "EnenA-B-C-ddE/s-VV";
                                 colorname();
                             }
    
                             else
                             {
                                 color = "Steel Opal";
                                 gtype = "enenA-B-C-ddE/s-VV";
                                 colorname();
                             }
                             break;
                     }
                            case 2:
                                if ((charlie == true) & (dilute == false))
                                {
                                    color = "charlie Steel Choc. Agouti";
                                    gtype = "EnEnA-bbC-D-E/s-VV";
                                    colorname();
                                }
    
                                else if
                                 ((broken == true) & (dilute == false))
                                {
                                    color = "Broken steel Choc. Agout";
                                    gtype = "EnenA-bbC-D-E/s-VV";
                                    colorname();
                                }
    
                                else if (dilute == false)
                                {
                                    color = "steel Choc. Agouti";
                                    gtype = "enenA-bbC-D-e/s-VV";
                                    colorname();
                                }
                                switch (offspring[8])
                                {
                                    case 1:
                                        break;
                                    case 2:
                                        if (charlie == true)
                                        {
                                            color = "Charlie Steel Lynx";
                                            gtype = "EnEnA-bbC-ddE/s-VV";
                                            colorname();
                                        }
    
                                        else if (broken == true)
                                        {
                                            color = "Broken Steel Lynx";
                                            gtype = "EnenA-bbC-ddE/s-VV";
                                            colorname();
                                        }
    
                                        else if (dilute == true)
                                        {
                                            color = "Steel Lynx";
                                            gtype = "enenA-bbC-ddE/s-VV";
                                            colorname();
                                        }
                                        break;
                                }
                        }
                
                return;
            }

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    All case sections MUST end with break. Fall-through is never permitted. The reason you can't find the spot where you've missed a break, is because your indentation is a disaster.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock problem
    By Wolf` in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2010, 04:55 PM
  2. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  3. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM