Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 18th, 2005, 12:13 AM   #1
strider496
Newbie
 
Join Date: Mar 2005
Posts: 10
Rep Power: 0 strider496 is on a distinguished road
stuck at this program

This is the program

A parking garage charges $2 for minimum fee to park up to 3 hours and then a $.50 per hour charge after the 3rd hour. The maximum charge for any 24 hour parking is $10. Assume no car parks longer than 24 hrs, write a program that calculates and prints the parking charge for each of 3 customer. Result should be printed in tabular format. Hint: use function called calculateCHarge to determine charge for each customer

#include <stdio.h>

minfee = 2;

int main()
{
	int car1,car2,car3,hour,hour2,hour3,charge1,charge2,charge3,
		totalhour,totalcharge,minfee;

	printf("Enter car number\n");
	scanf("%d", &car1);

	printf("How many hour did the car park\n");
	scanf("%d", &hour);

	if (hour>=3) {
		charge1 = (minfee+hour*.50); }

	else {
		charge1 = 2.00; }

	printf("Enter car number\n");
	scanf("%d", &car2);

	printf("How many hour did the car park\n");
	scanf("%d", &hour2);

	if (hour>=3) {
		charge2 = (minfee+hour*.50); }

	else {
		charge2 = 2.00; }

	printf("Enter car number\n");
	scanf("%d", &car3);

	printf("How many hour did the car park\n");
	scanf("%d", &hour3);

	if (hour>=3) {
		charge3 = (minfee+hour*.50); }

	else {
		charge3 = 2.00; }

	totalhour=(hour+hour2=hour3);
	printf("%d", totalhour);

	totalcharge=(charge1+charge2+charge3);
	printf("%d", totalcharge);

return 0;

}

Heres how output should be

Car Hours Charge
1 1.5 2.00
2 4.0 2.50
3 24.0 10.00
Total 29.5 14.50
strider496 is offline   Reply With Quote
Old Mar 18th, 2005, 1:54 PM   #2
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
looks like you got some debugging to do.
good luck with that
dizz
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Mar 18th, 2005, 2:31 PM   #3
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 5 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
I'll play around with it tonight and see if I can help out.
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old Mar 18th, 2005, 3:30 PM   #4
spydoor
Programmer
 
Join Date: Feb 2005
Posts: 64
Rep Power: 4 spydoor is on a distinguished road
the logic is mostly correct you just have a lot of bugs.

at first I thought dizz was being pompus (sorry dizz), but these are the types of bugs you need to learn to spot and fix easily, and the best way to do that is to pay attention to compiler errors and debug your own code. I went ahead and listed them out anyway... couldn't help myself

-global minfee has no datatype, or local minfee not initalized (you pick )
-ch arge3
-totalhour=(hour+hour2 = hour3);
-you need to use float instead of int for hours and charges
-you always use if(hour>=3) instead of appropriate hour, hour2, hour3
-you never print out the car specific info.. only the totals

half of these the compiler tells you about.....

by the way the instructions say to call a function to calculate the charge

Last edited by spydoor; Mar 18th, 2005 at 3:53 PM.
spydoor is offline   Reply With Quote
Old Mar 18th, 2005, 4:08 PM   #5
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
well, i'd appreciate a 'please' or a 'if you have time' once in a while, posting a homework question and expecting results is not a way to get around, a little respect is all i ask for.
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Mar 18th, 2005, 4:34 PM   #6
spydoor
Programmer
 
Join Date: Feb 2005
Posts: 64
Rep Power: 4 spydoor is on a distinguished road
No, I agree that's why I wrote at first.

Your response seemd appropriate after I realized most of the errors were simple typos or using the wrong variable from copying and pasting. Looks like there was little effort by the original poster to debug the code.

And like you said, this is clearly a homework problem which was posted without any specific question... guess that gets old quick.. I'm new to this board.

But really I meant nothing against you.. I was just apologizing for jumping to conclusions about the intent of your post from my first read of it.

Now I feel over apologetic anyway carry on.....
spydoor is offline   Reply With Quote
Old Mar 18th, 2005, 4:48 PM   #7
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
i understand, just letting people know my stance, there's a bunch of posts by me that aren't as nice.. no offence taken, no worries
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Mar 20th, 2005, 2:06 PM   #8
Monster
Newbie
 
Join Date: Jan 2005
Posts: 20
Rep Power: 0 Monster is on a distinguished road
That's something you can turn off.

Goto Project Settings (Alt+F7) then select the C/C++ tab.
Select Category: Precompiled Headers
Now select: Not using precompiled headers
Monster is offline   Reply With Quote
Old Mar 20th, 2005, 2:26 PM   #9
strider496
Newbie
 
Join Date: Mar 2005
Posts: 10
Rep Power: 0 strider496 is on a distinguished road
is there a way to calculate all the charges regardless of hours in 1 equation?
or i have to do if and else statements like wat i did above on the post.
strider496 is offline   Reply With Quote
Old Mar 20th, 2005, 4:13 PM   #10
strider496
Newbie
 
Join Date: Mar 2005
Posts: 10
Rep Power: 0 strider496 is on a distinguished road
revised program

#include <stdio.h>

int main()
{
	int car,counter=0;
	float minfee=2.00,maxfee=10.00,hours,totcharge,tothours,
		calculateCharge;

	totcharge=0;
	tothours=0;
	counter=1;

	while(counter<=3){ 
	
	  printf("enter car number\n");
	  scanf("%d",&car);

	  printf("enter hours parked\n");
	  scanf("%f",&hours);
		
		if(hours<4) {
			calculateCharge=minfee;
			printf("%.2f",calculateCharge);
		}
		if(hours<=24) {
			calculateCharge=(minfee+hours/2);
			printf("%.2f",calculateCharge);
		}
		else  {
			calculateCharge=maxfee;
			printf("%.2f",calculateCharge); 
		}
	counter=counter+1;
	}
	while(hours>=3) {
		calculateCharge=(minfee+hours/2);
	
	tothours=tothours+hours;
	printf("%.2f",tothours);

	totcharge=totcharge+calculateCharge;
	printf("%.2f",totcharge);

	return 0;
}

I dont know whats wrong with my program, it doesn't print out the tothours and totcharge.
strider496 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:43 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC