943,902 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 8563
  • C++ RSS
May 7th, 2004
0

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

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bryj3 is offline Offline
5 posts
since May 2004
May 7th, 2004
0

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

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
Reputation Points: 47
Solved Threads: 2
Junior Poster in Training
infamous is offline Offline
77 posts
since Mar 2004
May 11th, 2004
0

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

i think u should start with a pseudocode first.
Reputation Points: 14
Solved Threads: 0
Newbie Poster
ze_viru$ is offline Offline
21 posts
since May 2004
May 11th, 2004
0

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

TO ZE_VIRU$
Hey thanks ZE_VIRU$......I found the code from another sorce. It was a little longer but it worked....THANKS AGAIN
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bryj3 is offline Offline
5 posts
since May 2004
May 15th, 2005
0

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

i would be interested in knowing how you worked it out if you don't mind
Reputation Points: 10
Solved Threads: 0
Newbie Poster
schoolgirl05 is offline Offline
2 posts
since May 2005
May 15th, 2005
0

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

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.
Reputation Points: 35
Solved Threads: 3
Posting Whiz in Training
Dogtree is offline Offline
232 posts
since May 2005
Aug 15th, 2005
0

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

Here you go I hope this helps!!!

C++ Syntax (Toggle Plain Text)
  1. //Chapter 3 in C++ Programming
  2. //Parking Garage
  3. //Author Robert Capetillo 8-12-05
  4.  
  5. #include <iostream>
  6.  
  7. using std::cout;
  8. using std::cin;
  9. using std::endl;
  10. using std::fixed;
  11.  
  12.  
  13. #include <iomanip>
  14.  
  15. using std::setw;
  16. using std::setprecision;
  17.  
  18.  
  19. int main()
  20. {
  21. int count;
  22. int x;
  23. double charge;
  24. double a;
  25. double b;
  26. double c;
  27.  
  28. cout<< "Enter the number of Hours: ";
  29. cin >> a >> b >> c;
  30.  
  31.  
  32. cout<< setw(5)<< "Car" << setw(10)<< "Hours" << setw(15)<< "Charge\n";
  33.  
  34. cout << fixed << setprecision (2);
  35.  
  36. count = 1;
  37. while ( count <=3 ) {
  38.  
  39. if (count == 3)
  40. x = c;
  41.  
  42. else if (count == 2)
  43. x = b;
  44.  
  45. else if (count == 1)
  46. x = a;
  47.  
  48. if (x <= 3)
  49. charge = 2;
  50.  
  51. else if (x >19)
  52. charge = 10;
  53. else if (x > 3)
  54. charge = 2 + (x - 3) * (.5);
  55.  
  56. cout <<setw(5) << count<< setw(10) << x << setw(10)<< "$"<<charge <<"\n";
  57.  
  58. count = count + 1;}
  59.  
  60. return 0;
  61.  
  62. }
<< moderator edit: added code tags: [code][/code] >>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Twin6g72Turbo is offline Offline
1 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: C++ linking problem
Next Thread in C++ Forum Timeline: problem with tic-tac-toe! help.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC