17. Program that inputs a value and type of conversion. The program should then displays the output after conversion.

Chapter 5: 

Conditional Structures

Programming Exercise

Problem # 17:

Write a program that inputs a value and type of conversion. The program should
then displays the output after conversion. The program should include the following
conversions:
1 cm = .394 inches
1 liter = .264 gallons
1 kilometer = .622 miles
1 kilogram = 2.2 pounds

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    char V,x;
    int charges;
    cout<<"Select your vehicle:\nM\t=Motorcycle\nC\t=Car\nB\t=Bus";
    cin>>V;
    cout<<"Enter days to park the vehicle : ";
    cin>>x;
    switch(V)
    {
        case 'M':
        {
            charges=x*10;  
            cout<<"Charges for Motorcycle is Rs."<<charges ;
            break;  
        }
          
        case 'C':
        {
            charges=x*20;
            cout<<"Charges for Car is Rs."<<charges;
            break;
        }
           
        case 'B':
        {
            charges=x*30;
            cout<<"Charges for Bus is Rs."<<charges;
            break;
        }
           
        default:
            cout<<"Invalid input";
    }
    return 0;
}


Let me know in the comment section if you have any question.

Previous Post:
16. Program inputs the type of vehicle and number of days to park the vehicle. It finally displays the total charges for the parking.

Comments