I need some help for this task I have to have in soon. I'm writing the code using Quincy and have got all the basis down; but I'm just getting stuck on little fiddly bits which I'm unfamiliar with. EG local and global variables, calling and returning functions, if/else functions, etc.
Any help is appreciated.
Thanks
Task:
a) Prompt the user to input the vehicle type. ‘c’ or ‘C’ for a car, ‘m’ or ‘M’ for a motorbike, ‘t’ or ‘T’ for a truck. Display a message 'Wrong vehicle type' when the input character is other than specified.
b) Prompt the user to input the parking time in hours. The parking time is supposed to be a positive integer number greater that 0. Therefore, one hour minimum charge is applied. The program should validate the input time. Display a message 'Wrong parking time when parking time is invalid.
c) Calculates the amount charged based upon the following rates:
car - $5p/h, motorbike - $2p/h, truck - $10p/h
However, if parking time is longer than 4hrs, after that a 25% discount rate is applied ( after 4hrs ). If parking time is longer than 12hrs, after that 50% discount is applied ( to all period after 12hrs ).
d) Output the parking time and the parking fee
Code so far:
Code:
#include <stdio.h>
#include <stdbool.h>
#define CAR 5.0
#define MOTORBIKE 2.0
#define TRUCK 10.0
#define DISCOUNT1 0.25
#define DISCOUNT2 0.50
#define TIME1 4
#define TIME2 12
/* function prototypes */
bool validateVechileType(char type);
bool validateParkingTime(int hours);
double getParkingFee(char type, float hours, float fee);
void displayParkingFee();
float getParkingRate(float rate);
int main(void)
{
char type;
int hours;
float fee;
float rate;
bool validtype;
bool validtime;
printf("Enter your vehicle type (c, m or t): ");
scanf("%c", &type );
validtype = validateVehicleType( type);
if( validtype == true)
{
rate = getVehicleRate( type);
printf("Enter hours: ");
scanf("%f", &hours );
validtime = validateParkingTime( hours);
if( validtime == true)
{
fee = getParkingFee( hours, rate);
displayParkingFee;
}
else
{
printf("Wrong parking time");
return 0;
}
}
else
{
printf("Wrong vehicle type");
}
return 0;
}
/* validate the input vehicle type according to predefined values*/
bool validateVechileType(char type)
{
if (type == 'C' || 'c' || 'M' || 'm' || 'T' || 't')
return (true);
else
return (false);
}
/*assign apropriate value for rate*/
float getVehicleRate(char type)
if (type == 'C' || 'c')
{
rate = CAR;
}
if (type == 'T' || 't')
{
rate = TRUCK;
}
if (type == 'M' || 'm')
{
rate = MOTORBIKE;
return (rate);
}
/* validate the input parking time according to predefined values*/
bool validateParkingTime(int hours);
{
if (hours >> 0 && hours%1 == 0)
return (true);
else
return (false);
}
/*calculate and return the parking fee*/
float getParkingFee(int hours, float rate);
{
if (hours <= TIME1)
{
fee = rate * hours;
}
if (TIME1 < hours && hours <= TIME2)
{
fee = (rate * 4) + (rate * (hours - 4));
}
if (TIME2 < hours)
{
fee = (rate * 4) + (rate * DISCOUNT1 * 8) + (rate * DISCOUNT2 * (hours - 12));
}
return (fee);
}
/*display the calculated parking fee*/
displayParkingFee(char type, int hours, float fee );
{
if (type == 'C' || 'c')
printf("Car %d hrs parking fee: %.2f", hours, fee);
if (type == 'M' || 'm')
printf("Motorbike %d hrs parking fee: %.2f", hours, fee);
if (type == 'T' || 't')
printf("Truck %d hrs parking fee: %.2f", hours, fee);
return();
}