#include <stdio.h>
#define CAR_RATE 3
#define BUS_RATE 5
#define TRUCK_RATE 6
#define TRUE 1
#define FALSE 0
#define DISCOUNT 0.5
/* defining variables */
float Time, fee;
float C, c, B, b, T, t;
char Type;
/* function declarations */
int validateVehicleType(char vehicleType);
float validateParkingTime( float Time );
float calculateParkingFee( float car, float bus, float truck, int fee);
float displayParkingFee( int fee );
int main(void)
{
printf("Enter your vehicle type- Car = C, Bus = B, Truck = T :");
scanf("%c", &Type);
if(validateVehicleType(Type) == 0)
{
printf("Wrong vehicle type!");
return 1;
}
else
{
printf("Enter parking time (hours): ");
scanf("%f", &Time);
}
if( validateParkingTime( Time ) == 1)
printf("Correct Time Entered\n");
else if( validateParkingTime( Time ) == DISCOUNT)
fee = fee * 0.5;
else
printf("Incorrect Time Value - Restart Program\n");
displayParkingFee( fee );
}
/* function definitions */
int validateVehicleType(char Type)
{
switch(Type)
{
case 'c':
case 'C':
return TRUE;
break;
case 'b':
case 'B':
return TRUE;
break;
case 't':
case 'T':
return TRUE;
break;
default:
return FALSE;
}
}
float validateParkingTime( float Time )
{
if(Time < 1)
return(FALSE);
if((Time < 12) && (Time > 0))
return(TRUE);
if((Time > 12));
return(DISCOUNT);
}
float calculateParkingFee( float car, float bus, float truck, int fee)
{
if((Type = C) || ( Type = c))
fee = CAR_RATE * Time;
if((Type = B) || ( Type = b))
fee = BUS_RATE * Time;
if((Type = T) || ( Type = t))
fee = TRUCK_RATE * Time;
else
printf("Invalid Value\n");
}
float displayParkingFee( int fee )
{
printf("%c parking fee is %d. \n", Type, fee);
}