Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main(){
- //Declare variables
- char vehicleType;
- int hourVehicleEnter, minuteVehicleEnter, hourVehicleLeft, minuteVehicleLeft, timeInHour, timeInMin;
- float firstRate = 0, secondRate = 0, totalRate = 0;
- //Ask the user to enter car type and time
- printf("Enter the type of vehicle: ");
- scanf("%c", &vehicleType);
- printf("Enter the hour the vehicle entered the lot(0-24): ");
- scanf("%d", &hourVehicleEnter);
- printf("Enter the minute the vehicle entered the lot(0-60): ");
- scanf("%d", &minuteVehicleEnter);
- printf("Enter the hour the vehicle left the lot(0-24): ");
- scanf("%d", &hourVehicleLeft);
- printf("Enter the minute the vehicle left the lot(0-60): ");
- scanf("%d", &minuteVehicleLeft);
- //Calculate time difference
- timeInHour = abs(hourVehicleLeft - hourVehicleEnter);
- timeInMin = 60 - (abs(minuteVehicleLeft - minuteVehicleEnter));
- //Round up hours
- if(timeInMin > 0){
- timeInHour++;
- }
- //Calculate the rate based on the vehicle choice
- if((vehicleType == 'C') || (vehicleType == 'c')){
- if(timeInHour > 3){
- secondRate = 1.50 * (timeInHour - 3);
- }else{
- firstRate = 0;
- }
- totalRate = secondRate + firstRate;
- //Output the result
- printf("Type of Vehicle: Car");
- printf("\nTIME-IN: %d : %d ", hourVehicleEnter, minuteVehicleEnter);
- printf("\nTIME-OUT: %d : %d ", hourVehicleLeft, minuteVehicleLeft);
- printf("\n-------");
- printf("\nPARKING TIME: %d : %d ", (timeInHour - 1), timeInMin);
- printf("\nROUNDED TOTAL: %d", timeInHour);
- printf("\n-------");
- printf("\nTOTAL CHARGES: $%.2f", totalRate);
- }
- if((vehicleType == 'T') || (vehicleType == 't')){
- if(timeInHour > 2){
- secondRate = 2.30 * (timeInHour - 2) + 2;
- }else{
- firstRate = 1.00 * timeInHour;
- }
- totalRate = secondRate + firstRate;
- //Output the result
- printf("Type of Vehicle: Truck");
- printf("\nTIME-IN: %d : %d ", hourVehicleEnter, minuteVehicleEnter);
- printf("\nTIME-OUT: %d : %d ", hourVehicleLeft, minuteVehicleLeft);
- printf("\n-------");
- printf("\nPARKING TIME: %d : %d ", (timeInHour - 1), timeInMin);
- printf("\nROUNDED TOTAL: %d", timeInHour);
- printf("\n-------");
- printf("\nTOTAL CHARGES: $%.2f", totalRate);
- }
- if((vehicleType == 'B') || (vehicleType == 'b')){
- if(timeInHour > 1){
- secondRate = 3.70 * (timeInHour -1) + 2;
- }else{
- firstRate = 2.00 * timeInHour;
- }
- totalRate = secondRate + firstRate;
- //Output the result
- printf("Type of Vehicle: Bus");
- printf("\nTIME-IN: %d : %d ", hourVehicleEnter, minuteVehicleEnter);
- printf("\nTIME-OUT: %d : %d ", hourVehicleLeft, minuteVehicleLeft);
- printf("\n-------");
- printf("\nPARKING TIME: %d : %d ", (timeInHour - 1), timeInMin);
- printf("\nROUNDED TOTAL: %d", timeInHour);
- printf("\n-------");
- printf("\nTOTAL CHARGES: $%.2f", totalRate);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment