help converting if/else to a switch statement plzz

if( vehicleUse == 'C' ) // Carpool
{
// TODO: Convert to a switch statement

if( vehicleLoad == 'E' ) // 6-8
cout << "Ford Windstar" << endl;
else if( vehicleLoad == 'F' ) // 8-10
cout << "Dodge RAM Van" << endl;
else if( vehicleLoad == 'G' ) // 10-16
cout << "Blue Bird Mini Bus" << endl;
else // A-B-C-D
cout << "Consider a smaller vehicle." << endl;
}
else if( vehicleUse == 'F' ) // Family
{
// TODO: Convert to a switch statement

if( vehicleLoad == 'C' ) // 3-4
cout << "Ford Thunderbird" << endl;
else if( vehicleLoad == 'D') // 4-6
cout << "Pontiac Grand Prix" << endl;
else // A-B, E-F-G
cout << "Consider a smaller or larger vehicle."
<< endl;
}
else if( vehicleUse == 'S' ) // Sport
{
// TODO: Convert to a switch statement

if( vehicleLoad == 'A' ) // 1-2
cout << "Dodge Viper" << endl;
else if( vehicleLoad == 'B' ) // 2-3
cout << "Ford Mustang" << endl;
else // C-D-E-F-G
cout << "Consider a larger vehicle." << endl;
}
else // Invalid vehicle use
cout << "You entered an invalid choice: "
<< vehicleUse << endl;


cout << "\nEnd Program" << endl;

return 0;
}
LOL..

There is a tutorial for this one.
It is very easy to understand..

Ex.

1
2
3
4
5
6
7
8
9
10
11
12
if (UserName == 'jem')
     {
          cout << "Handsome";
     }

     else if (UserName == 'joey')
     {
          cout << "Not Handsome!";
     }

     else
          cout<< "Intelligent";


is equivalent to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

switch (UserName)
{
     case 'jem':
     {
     cout << "handsome!";
     break;
     }

     case 'joey':
     {
     cout << "Not Handsome!";
     break;
     }

     default:
     {
     cout << "Intelligent";
     break;
}
}
Topic archived. No new replies allowed.