This code take input from the user (characters C,T,B) and (int 0-24 and 0-60) to calculate the cost of parking based on the type of vehicle the user inputs.
the last line of code in the program is supossed to print the result of the function "charged" which is determined by the type of vehicle declared by the user inputed char value but when i run it only retruns 0.00 instead of the flaot value any and all help is appreciated :)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int total_minute_parked (int minute_in, int minute_left)
{
int minute_parked;
if (minute_in > minute_left)
{
minute_parked = (minute_left - minute_in + 60);
}
else
{
minute_parked = (minute_left - minute_in);
}
return minute_parked;
}
// func calc total hours parked
int total_hour_parked (int hour_in, int hour_left)
{
int hours_parked;
if (hour_left > hour_in)
{
hours_parked = abs((hour_left - 1) - hour_in);
}
else
{
hours_parked = abs(hour_left - hour_in);
}
return hours_parked ;
}
// -------------------funtion to calc charge based off type of vehicle------
float charged (char vehicle_type,int total_hour_parked)
{
char C;
char T;
char B;
float temp_charged;
if (vehicle_type == C) // -------------------------------CAR
{
if (total_hour_parked > 3)
{
float secondary_hour = total_hour_parked - 3;
temp_charged = secondary_hour * 1.5;
}
else
{
temp_charged = 0;
}
}
else if (vehicle_type == T) // ------------------------------TRUCK
{
if (total_hour_parked > 2)
{
float secondary_hour = total_hour_parked - 2;
temp_charged = (secondary_hour * 2.3) + 1.0;
}
else {
temp_charged = 1;
}
}
else if (vehicle_type == B) // -----------------------------------BUS
{
if (total_hour_parked > 1)
{
float secondary_hour = total_hour_parked - 1;
temp_charged = (secondary_hour * 3.7) + 2.0;
}
else {
temp_charged = 2;
}
}
return temp_charged;
}
//---------------------- end program upon invalid imput -------------------//
// --------------------- main that prints results and takes imput -----------//
int main()
{
int total_hour_parked (int hour_in,int hour_left);
float charged (char vehicle_type, int total_hour_parked);
char vehicle_type;
int hour_in = 0;
int minute_in = 0;
int hour_left = 0;
int minute_left = 0;
printf("Please enter the type of Vehicle:");
scanf("%c",&vehicle_type);
printf("Please enter the hour entered lot:");
scanf("%d", &hour_in);
printf("Please enter the minute entered lot:");
scanf("%d", &minute_in);
printf("Please enter the hour left lot:");
scanf("%d", &hour_left);
printf("Please enter the minute left lot:");
scanf("%d", &minute_left);
printf("------------------------------------\n");
printf("Parking time: %d:%d\n", total_hour_parked(hour_in,hour_left),total_minute_parked(minute_in,minute_left));
printf("Cost %f",charged(vehicle_type,total_hour_parked));
return 0;
}
vehicle_type == 'C'? Becausevehicle_type == Cmakes no sense as the variableCis uninitialized and will have an indeterminate (and seemingly random) value.if (vehicle_type == C)make no sense, when the variableChas no determinate value. I concur with Some programmer dude. It looks like you want to use character literals in this. The final printf arguments don't make much sense either.int total_hour_parked (int hour_in,int hour_left);declares a function. Passing it as an argument (uncalled, so a function pointer) tochargedmakes no sense.