Hi everyone,
I need help writing a program.. I have no idea how to start off ...can you please help me...I am very lost :sad: Thank you soo much if you can help because I am extremely confused.

A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour or part thereof in excess of three hours. The maximum charge for any given 24 hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the number of hours parked for each customer. Your program should print the results in a net tabular format and should calculate and print the total of yesterday's receipts. The program should use the function calculateCharges to determine the charge for each customer.

-Use a for loop to prompt the user for the number of hours parked for each of the three customers.

-Declare variables to store the total number of hours and the total charges for each customer

-The variable for all charges and numbers of hours should be of type double

-Function calculateCharges should use a nested if/else structure to determine the customer charge.

I recommend starting by giving yourself input and calculating the results by hand. Ask yourself, "What steps am I doing to solve this problem?" Then write down on paper exactly what one does to solve the problem.

If you can describe the problem completely, then writing your computer program is just a matter of translation. This is a good programming strategy for when you are first starting out.

hi here is the solution for your problem.

#include "stdio.h"
#define NUM_CUSTOMERS 3
main()
{
	int num_hours ,customers;
	float charge_min = 2.0,rate = 0.5 , charge_max = 10.;
	float calculate_charge;

	for(customers=1;customers<= NUM_CUSTOMERS ; ustomers++)
	{
		printf("enter the number of hours\n");
		scanf("%d",&num_hours);
		if(num_hours<=3)
		calculate_charge = charge_min;
		else
		{ if (num_hours<19)
			calculate_charge = charge_min + rate*(num_hours -3);
		  else calculate_charge = 10.;
		}
	printf("charge = %f\n",calculate_charge);
	} // end of for loop.
}// end of main.

<< moderator edit: added [code][/code] tags >>

run the above code and get the disired result . it wont printf in tabular formate.

>hi here is the solution for your problem.
Wonderful, yet another helpful bozo who's willing to teach beginners to be ignorant and rely on others to do their work for them.

>run the above code and get the disired result
Maybe, but then again, maybe not. Your entire program is undefined, and even if it weren't, it's littered with poor practices. I suggest you learn C before trying to teach it. Here are a few of the problems:

>#include "stdio.h"
It's conventional to use angle brackets for standard library headers and double quotes for everything else. When you use double quotes for standard headers, it suggests that you haven't used C long enough to know how code is expected to look. Also, most implementations search different locations first depending on whether <> or "" is used. By using "stdio.h", you may be forcing the implementation to unsuccessfully search a bunch of places before actually finding stdio.h. On the other hand, <> is more likely to search the correct path first.

>main()
This is correct:

int main ( void )

>float
There's no reason to use float. In fact, float may be less efficient than double, which is the default for floating-point constants. If you really think you're smart and float is the best choice, append f or F onto the end of every floating-point constant to be strictly correct.

>for(customers=1;customers<= NUM_CUSTOMERS ; ustomers++)
The only excuse for this is sheer stupidity. Aside from the obvious syntax error of using "ustomers", starting a loop at 1 rather than 0 and using <= instead of < defeats the concept of asymmetric bounds to make correctness checking simple and it encourages fencepost errors.

>scanf("%d",&num_hours);
I don't care how inexperienced someone is, you always set a good example by testing input functions for errors and end-of-file. There's no excuse to use a bare scanf, and the correct usage is something like this:

if ( scanf ( "%d", &num_hours ) != 1 ) {
  /* Handle error or EOF */
}

>if(num_hours<=3)
"Up to" means "up to, but not including". So you're actually charging the minimum for four hours rather than three.

>}// end of main.
This is where the undefined behavior is. You say you're going to return int, but you don't return anything.

On top of all of that, ignoring poor formatting, you "solved the problem" but failed to meet most of the requirements. So not only did you break the rules by doing the OP's homework, you did it with a very bad solution.

>main()
This is correct:

int main ( void )

int main() is also acceptable, at least with C99.

>}// end of main.
This is where the undefined behavior is. You say you're going to return int, but you don't return anything.

Note that he didn't actually say he was going to return int ;-)
With the C99 standard, if main has no return statement, then return 0 is assumed. Portability to older compilers is of course desirable though.

>int main() is also acceptable, at least with C99.
With C89 as well, but it's not semantically consistent with K&R-style function declarations. Rather than try to explain that an empty parameter list is okay in a definition but grievously broken in a declaration, it's better to simply recommend void.

>Note that he didn't actually say he was going to return int ;-)
Yes, he did. Since he's obviously compiling as C89, int is assumed when no return type is stated explicitly.

>With the C99 standard, if main has no return statement, then return 0 is assumed.
With the lack of C99 implementations, relying on a C99 feature that would be undefined in C89 is the height of stupidity.

>Portability to older compilers is of course desirable though.
You say this as if I couldn't grab half a dozen modern and popular compilers and fail to compile the simplest of C99 programs on all of them. ;)

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.