Write a program to calculate the parking fare for customers who park their cars in a parking lot when the following information is given:
a. A character showing the type of vehicle: C for car, B for bus and T for truck
b. An integer between 0 and 24 showing the hour the vehicle entered the lot.
c. An integer between 0 and 60 showing the minute the vehicle entered the lot.
d. An integer between 0 and 24 showing the hour the vehicle exited the lot.
e. An integer between 0 and 60 showing the minute the vehicle exited the lot.
As it’s a public lot, people are encouraged to park for only a short period of time. The management uses two different rates for each type of vehicle.
No vehicle is allowed to stay in the parking lot later that midnight; it will be towed away. There is also a GST of 6% on the parking charges.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char type; //type of vehicles
int totalMinParked, totalHourParked; //total hour and minute parked
int hourIn, minIn, hourOut, minOut; //time showing the vehicles enter and exit in hours and minutes
float totalChargeFee; //the total price of user's parking charge fee
printf("---Parking Lot Charge---\n"); //introduction message
printf("Enter type of vehicle: %c", type);
scanf("%c", &type);
printf("Enter hour in:");
scanf("%d", &hourIn);
printf("Enter minute in:");
scanf("%d", &minIn);
printf("Enter hour out:");
scanf("%d", &hourOut);
printf("Enter minute out:");
scanf("%d", &minOut);
if(type == 'C' && totalHourParked <= 3)
{
totalChargeFee = 0.8 * totalHourParked;
}
else
{
totalChargeFee = 1.5 * totalHourParked;
}
if(type == 'T' && totalHourParked <= 2)
{
totalChargeFee = 1.5 * totalHourParked;
}
else
{
totalChargeFee = 2.3 * totalHourParked;
}
if(type == 'B' && totalHourParked <= 1)
{
totalChargeFee = 2 * totalHourParked;
}
else
{
totalChargeFee = 3.4 * totalHourParked;
}
printf("Your total charge fee: %.2f", totalChargeFee);
scanf("%lf", &totalChargeFee);
return 0;
}
I don't know how to make it calculate the time in and time out with hours and minutes difference and also the type of vehicles.
Aucun commentaire:
Enregistrer un commentaire