+ 1
Can we use multiples switch statements in just one program?
eg: { int a=5,good=10, excellent=15; switch(a) { case 5: cout<<"good"<<endl; break; switch (good) { case 10: cout<<"Excellent"<<endl; break; switch (excellent) { case 15: cout<<"superb"<<endl; break; default: cout<<"worst"<<endl; }}} return 0; }
1 Respuesta
+ 2
Yes we can, but need to pay attention, put the nested switch block BETWEEN the 'case' and 'break' statement of the outer switch block;
int x {60}, y {70}, z {80};
switch(x)
{
    case 60:
        switch(y)
        {
            case 60:
                // x & y = 60
                break;
            case 70:
                // x = 60, y = 70
                break;
            case 80:
                // x = 60, y = 80
                break;
        }
        break;
    // more cases for x here ...
}



