16. Program inputs the type of vehicle and number of days to park the vehicle. It finally displays the total charges for the parking.
Chapter 5:
Conditional Structures
Programming Exercise
Problem # 16:
Write a program that displays the following menu for a parking area:
M =Motorcycle
C =Car
B =Bus
The program inputs the type of vehicle and number of days to park the vehicle. It
finally displays the total charges for the parking according to the following:
Motorcycle Rs. 10 per day
Car Rs. 20 per day
Bus Rs. 30 per day
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;
}
#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:
15. Program that inputs year and month. It displays the number of days in the month of the year entered by the user.
Comments
Post a Comment