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

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

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

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.

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] >>

This article has been dead for over six months. Start a new discussion instead.