I have been given the following assignment:
Write a function (documentation included) that given the entry and the
exit time of a vehicle in a parking lot, and the hourly rate,
calculates the amount due.Assumptions:
- no overnight parking
- there is no charge for part of an hour
- the time is given in military style (1:20p.m. is 1320)
You also have to write a test-driver for your function: in main()
declare and initialize as many variables as needed, then call the
function and display the amount.
This is the code:
int calcRate (int entry , int exit);
int main (void)
{
// Local Declarations
int entry;
int exit;
//Statements
printf("Please Enter Entry and Exit time(In military style. For example : 9.30am as
0930)\n");
scanf("%d %d\n",&entry , &exit);
double fee = calcRate(entry,exit);
printf("Your Parking Fees are %f\n", fee);
return 0;
} //main
/*==============calcRate================
This function calculates the cost of parking
*/
double calcRate (int entry,int exit,double cost)
{
int hours;
double rate = 2.00;
//Statements
hours = (exit-entry)/100;
cost = hours * rate;
return (cost);
}
//calcRate
I cannot build it and I am facing problems with it. For example, I get the following error:
Undefined symbols for architecture x86_64: “calcRate(int, int)”, referenced from: _main in Parking.o (maybe you meant: calcRate(int, int, double)
I’m stuck for almost 2 hours now.
Any kind souls out there?
Difference between function declaration and definition
Function Declarations
Definition header
So either change Declaration or definition header
for Eg:
Change definition header to
and add declare
within function calcRate.
Instead of
Do
No “\n” within scan.
EDIT:
In case of overnightparking
Instead of
use
This will remove negative value.