Code:
//copyright emailroy2002! FTW!
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
void getData(char &vtype, int &ehour, int &emin, int &xhour, int &xmin);
void calculate_charges(char &vtype, int &eh, int &em, int &xh, int &xm);
void get_parking_rates(char vtype, double total_hrs, double totalmins);
int main(void)
{
char vtype;
int ehour;
int emin;
int xhour;
int xmin;
getData(vtype, ehour, emin, xhour, xmin);
calculate_charges(vtype, ehour, emin, xhour, xmin);
getch();
return 0;
}
void getData(char &vtype, int &ehour, int &emin, int &xhour, int &xmin)
{
printf("Enter C for car, B for bus, T for truck: ");
scanf("%c", &vtype);
printf("\nHour vehicle entered 0-24: ");
scanf("%d", &ehour);
printf("\bMin vehicle entered: ");
scanf("%d", &emin);
printf("\nHour vehicle left 0-24: ");
scanf("%d", &xhour);
printf("\bMinuite vehicle left: ");
scanf("%d", &xmin);
}
void calculate_charges(char &vtype, int &eh, int &em, int &xh, int &xm)
{
int start;
int end;
int totaltime;
double totalmins;
double total_hrs;
start = (eh * 60) + em;
end = (xh * 60) + xm;
totaltime = (end - start);
total_hrs = (totaltime / 60);
totalmins = ( totaltime % 60 );
if (eh > 24 || xh > 24) {
printf ("\nYour Automobile has been towed away!");
} else {
printf ("\nAutomobile type %c Entered At %d : %d : Exited at %d : %d \n", vtype, eh, em, xh, xm);
get_parking_rates(vtype, total_hrs, totalmins);
}
}
void get_parking_rates(char vtype, double total_hrs, double totalmins) {
double parking_rate;
double total_parking_fee;
//self explainatory (add more calculation for parking here
if (vtype == 'c') {
parking_rate = 10.50;
} else {
parking_rate = 25.50;
}
//printf ("\nAutomobile type %c Entered At %d : %d : Exited at %d : %d \n", vtype, ehour, emin, xhour, xmin);
printf("\n\n\bTotal Parking Time : %f hours and %f minutes " , total_hrs, totalmins );
total_parking_fee = total_hrs * parking_rate;
printf("\n\n\bTotal Parking charge %f" , total_parking_fee);
}