How to convert switch statements to if-else

Hello ,
I have been trying to make a complicated program.First I tried switch statements but that didn't work then I tried to change it to if else , but I couldn't do that .Can anyone please tell me how to change the following switch statements to if else ?

switch (x)
{
case 'm':
case 'M':
cout << "enter the fuel used";
cin>>FuelUsed;
cout<<"enter mileage ";
cin>>Mileage;
cout<<MilesperGal(FuelUsed,Mileage);
;
break ;

case 'd':
case 'D':
cout << "enter the fuel used";
cin>>FuelUsed;
cout<<"enter MPG ";
cin>>MilesPerGal;
cout <<mileage(FuelUsed,MilesPerGal );
break ;

case 'g':
case 'G':
cout << "enter the Mileage used";
cin>>Mileage;
cout<<"enter mileage ";
cin>>MilesPerGal;
cout<<fuelUsed (Mileage,MilesPerGal) ;
break;


default:cout<<"Wrong choice";
break; }
getch();
}
Please use [[b][/b]code][/[b][/b]code] tags when posting code
1
2
3
4
5
6
7
if ( x=='m' || x=='M') //case 'm': case 'M':
    //...
else if ( x=='d' || x=='D') //case 'd': case 'D':
    //...
//...
else //default:
    //.... 
Last edited on
Topic archived. No new replies allowed.