954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I need to write a C++ Code from the following info. HOW DO I...

Hello...
Any idea how to write this in C++ code....
A parking garage chages a $2.00 minimum fee to park up to three hours.
The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no cars park for longer than 24 hours at a time.

How do I write a program that calculates and prints the parking charges for each of the three customers who parked their cars in this garage yesterday.
Entering the hours parked for each customer. The program should print the results in a neat tabular format and should calculate and print the total of yesterday's receipts. The program should use the calculateCharges to determine the charge for each customer. The output should appear in the following format:

Car Hours Charge

1 1.5 2.00
2 4.0 2.50
3 24.0 10.00

Total 29.5 14.50


THANK YOU,
George

bryj3
Newbie Poster
5 posts since May 2004
Reputation Points: 10
Solved Threads: 0
 

read in the number of hours from the user using cin.
if the number is <= 3, then charge is 2
else if the (number of hours - 3) * .50 + 2 > 10, it is $10
else the answer is (number of hours - 3) * .50 + 2
use the cout formatting w/ ios:: crap to tabulate it

infamous
Junior Poster in Training
77 posts since Mar 2004
Reputation Points: 47
Solved Threads: 2
 

i think u should start with a pseudocode first.

ze_viru$
Newbie Poster
21 posts since May 2004
Reputation Points: 14
Solved Threads: 0
 

TO ZE_VIRU$
Hey thanks ZE_VIRU$......I found the code from another sorce. It was a little longer but it worked....THANKS AGAIN

bryj3
Newbie Poster
5 posts since May 2004
Reputation Points: 10
Solved Threads: 0
 

i would be interested in knowing how you worked it out if you don't mind

schoolgirl05
Newbie Poster
2 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

The last post was 05-11-2004 06:51 PM, over a year ago. Somehow I don't think bryj3 will have saved the code, even if he still hangs around here and sees your post.

Dogtree
Posting Whiz in Training
233 posts since May 2005
Reputation Points: 35
Solved Threads: 3
 

Here you go I hope this helps!!!

//Chapter 3 in C++ Programming
//Parking Garage
//Author Robert Capetillo 8-12-05

#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::fixed;


#include <iomanip>

using std::setw;
using std::setprecision;


int main()
{	
	int count;
	int x;
	double charge;
	double a;
	double b;
	double c;

	cout<< "Enter the number of Hours: ";
	cin >> a >> b >> c;

	
	cout<< setw(5)<< "Car" << setw(10)<< "Hours" << setw(15)<< "Charge\n";		

		cout << fixed << setprecision (2);

	count = 1;
	while ( count <=3 ) {
		
		if (count == 3)
			x = c;

		else if (count == 2)
			x = b;

		else if (count == 1)
			x = a;

	if (x <= 3)
		charge = 2;

		else if (x >19)
			charge = 10;
		else if (x > 3)
			charge = 2 + (x - 3) * (.5);

		cout <<setw(5) << count<< setw(10) << x << setw(10)<< "$"<<charge <<"\n";

count = count + 1;}
	
	return 0;

}


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

Twin6g72Turbo
Newbie Poster
1 post since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You