Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void Tax(float *gct, int *price_car, int *price_truck, int *price, float *finalprice, int *minutes_max, int *hours_max, char *vehicle);
int main(void)
{
char vehicle[6];
int hrsn; //Hour the vehicle entered the parking lot
int minn; //Minute the vehicle came in the parking lot
int hrso; //Hour the vehicle left the parking lot
int mino; //Minute the vehicle left the parking lot
int hr; //final hour
int min; //final minute
int minutes_max;//60 minutes
int hours_max;//24 hours
int price;
int price_car;
int price_truck;
int i, length;
float finalprice;
float gct;
hrsn=0;
hrso=0;
minn=0;
mino=0;
hr=0;
min=0;
minutes_max=0;
hours_max=0;
price=0;
finalprice=0;
gct=0.175; //17.5%
price_car=0;
price_truck=0;
printf("\n\nWhere you driving a car or truck?\n");
scanf("%s", &vehicle );
while( strcmp( vehicle, "truck" ) != 0 && strcmp( vehicle, "car" ) != 0 )
{
printf("Please input the words Car or Truck: ");
scanf("%s",&vehicle);
}
length = strlen(vehicle);
for (i=0; i<length; i++)
{ //change all vehicle letters to lowercase
vehicle[i] = tolower(vehicle[i]);
}
printf("What Hour did the %s enter the lot? (0-23)\n", vehicle);
scanf("%d",&hrsn);
while((hrsn<0 || hrsn>23))
{
printf("\a\a\a Please Input Value from 0-23!\n");
scanf("%d",& hrsn);
}
printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);
scanf("%d",& minn);
while((minn<0 || minn>59))
{
printf("\a\a\a Please Enter Correct Minute Between 0-59!\n");
scanf("%d",& minn);
}
printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);
scanf("%d",& hrso);
while((hrso<0 || hrso>23))
{
printf("\a\a\a Please Enter the Correct Time Between 0-23!\n");
scanf("%d",& hrso);
}
printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);
scanf("%d",& mino);
while(mino<0 || mino>59)
{
printf("\a\a\a PLease Enter the Correct time between 0-59!\n");
scanf("%d",& mino);
}
if(minn < mino)
{
minutes_max = 60 - (mino - minn);
//minutes_max = 60 - 5
//minutes_max = 55 minutes
}
else if(minn > mino)
{
minutes_max = (60 - minn) + mino;
hrso = hrso-1;
}
else
{
minutes_max = 0; //minutes_in equals minutes_out
}
if (hrsn < hrso)
{
hours_max = 24 - (hrso - hrsn);
}
else if (hrsn > hrso)
{
hours_max = (24 - hrso) + hrsn;
}
else
{
hours_max = 0;
}
hours_max = (hrso - hrsn);
printf("Time in %d:%d\n", hrsn, minn);
printf("Parking Time: %d hours:%d minutes\n", hours_max, minutes_max);
Tax(&gct,&price_car,&price_truck,&price,&finalprice,&minutes_max,&hours_max,vehicle);
return 0;
}
void Tax(float *gct, int *price_car, int *price_truck, int *price, float *finalprice, int *minutes_max, int *hours_max, char *vehicle)
{
if((strcmp(vehicle, "car")) == 0)
{
printf("The price for the car will be shown shortly:\n");
if( *minutes_max > 1 && *minutes_max < 30)
{
*price = *price_car + 50;
}
else if(*minutes_max > 30 && *minutes_max < 60)
{
*price = *price_car + 100;
}
else if( *hours_max >= 1)
{
*price = (*price_car+100) * *hours_max;
}
*finalprice = (*gct * *price) + *price;
printf("The Final Price is: %f\n", *finalprice);
}
else
//if((strcmp(vehicle, "truck")) == 0)
{
printf("The Price for the truck will be shown shortly\n");
if( *minutes_max > 1 && *minutes_max < 30)
{
*price = *price_truck + 100;
}
else if(*minutes_max > 30 && *minutes_max < 60)
{
*price = *price_truck + 150;
}
else if( *hours_max >= 1)
{
*price = (*price_truck+200) * *hours_max;
}
*finalprice = (*gct * *price) + *price;
printf("The Final Price is: %f\n", *finalprice);
}
}