Hello all,

I have an assignment that seems to be fairly popular. I've done some searches to see if I could resolve my issue but haven't stumbled across the exact problem I'm having.

This is the assignment:

A parking garage charges a \$2.00 minimum fee to park for up to three hours. The garage charges and additional \$0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24 your period is \$10.00. Assume that no car parks for longer than 24 hours and a time. Write a program that will calculate and Print the parking charges for each of three customers who parked their cars in the garage yesterday . You should enter the hours parked for each customer your program should print the results in a neat tabular format, and should calculate and print the total of yesterdays's receipts. The program should use the function calculateFee to determine the charge for each customer. you outputs should match the output of the file runme_part2

create a function that returns a dollar amount and takes the time as its one argument ie...

float CalculateFee( float time);

I am having problems getting my value to print out correctly. There seems to be an error in my math somewhere but I feel like I am missing it.

``````#include <stdio.h>

float CalculateFee(float time)
{
float charge;

if (time <= 3.0)
{
charge = 2.00;
}
else if ( time > 3.0 && time <= 19.0)
{
charge = 2.00 + ((time - 3) * 0.50);
}
else
{
charge = 10.00;
}
return charge;
}
int main(float time, float charge)
{

printf("How long did car 1 stay?   ");
scanf("%f", &time);

CalculateFee;

printf("Car 1 pays a fee of %.2f\n", charge);

return 0;
}``````

The program compiles, and when I run it, I can enter a number in for the program to calculate (this is just my test run, not trying to make the table or anything yet, just want the math to work). However, once I hit enter, it returns something along the lines of

Car 1 pays a fee of -1.45

for any value I put in.

Any suggestions are much appreciated!

## All 3 Replies

``````float CalculateFee(float time)
{
float charge = 2.0F;
if( time > 3.0F)
{
charge += (time-3.0F) * 0.50F;
if( charge > 10.0F)
charge = 10.0F;
}
return charge;
}``````

Hmm. I tried replacing my CalculateFee function with that one, and when I compiled it, ran it, and entered "2" for "How long did car 1 stay?", it still returned a value of -1.08.

I'm not really sure what those Fs are for, either. Would you mind explaining? I'm very new to this whole programming thing.

0.5 is a double, but 0.5F is a float -- the F tells the compiler to assume its a float and not a double.

>>int main(float time, float charge)

That is wrong. It sould be this:

``````int main(int argc, char* argv[])
{
float time,charge;
printf("How long did car 1 stay?   ");
scanf("%f", &time);

charge = CalculateFee(time);

printf("Car 1 pays a fee of %.2f\n", charge);

return 0;
}``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.