944,048 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1331
  • C++ RSS
May 27th, 2006
0

PLZ help me !!

Expand Post »


I have to submit the assignment tomorrow i got stuck in something looks silly the question is:
parking garage charges a $2.00 miniumum fee to pack for 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 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 hours parked for each customer.
Your program should print the results in a neat tubular format and should calculate
and print the total of yesterday’s receipts. The program should A parking garage charges
a $2.00 miniumum fee to pack for 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 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 hours
parked for each customer. Your program should print the results in a neat tubular 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.



and my solution is


C++ Syntax (Toggle Plain Text)
  1. //Hours and Charges for three cars which parked yesterday
  2. #include <iostream>
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6. using std::fixed;
  7.  
  8. #include <iomanip>//parameterized stream manipulators
  9. using std::setw;//The output appears in a field width of 10
  10. using std::setprecision; //sets numeric output precision
  11.  
  12. int main()
  13. {
  14.  
  15.  
  16. double TotalHours, //using the double to use the variables with decimal points
  17. a,
  18. hr1,hr2,hr3,
  19. charge,
  20. calculateCharges;
  21. //Intialization phase
  22. calculateCharges=0;
  23.  
  24. //Processing phase
  25. cout<< "Enter the hours parked for three cars : ";//prompt for input
  26. cin >> hr1 >> hr2 >> hr3;//input the hour of each of the three cars
  27.  
  28. cout<< setw(5)<< "Car" << setw(10)<< "Hours" << setw(15)<< "Charges\n\n";
  29. cout<<fixed<<setprecision(2); //sets numeric output precision
  30. for(int counter=1;counter<=3;counter++) {//loop 3 times and in every loop the counter is incremented by 1
  31.  
  32. if (counter == 1)
  33. a = hr1;
  34. else if (counter == 2)
  35. a = hr2;
  36. else if (counter == 3)
  37. a = hr3;
  38. if (a <= 3)
  39. charge = 2;
  40. else if (a >19)
  41. charge = 10;
  42. else if (a > 3)
  43. charge = 2 + (a - 3) * (0.5);
  44.  
  45.  
  46.  
  47. cout <<setw(5) << counter<< setw(10) <<setprecision(2)<< a << setw(10)<< charge <<"\n\n";
  48.  
  49. calculateCharges+=charge;//in every loop the Sum of the charges is incremented according to the value of the charge
  50. }
  51. //Termination phase
  52.  
  53. TotalHours=hr1+hr2+hr3;//It gives the total of the hours parked for three cars
  54.  
  55. cout<<" "<<"Total"<<setw(7)<<TotalHours<<setw(10)<<calculateCharges<<"\n\n"<<endl;
  56.  
  57. return 0; //successful termination
  58. }


the problem that when the time is shown it has to be only with one decimal point not to decimal points for example if it is 2.40 i need it to be 2.4

Help me plz
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
takayuki is offline Offline
1 posts
since May 2006
May 27th, 2006
0

Re: PLZ help me !!

Have you tried changing the paremeter for setprecision to see how it affects the output?
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
May 27th, 2006
0

Re: PLZ help me !!

Remove fixed.
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 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.
Message:
Previous Thread in C++ Forum Timeline: How to read Matlab Variabls in C++
Next Thread in C++ Forum Timeline: Export Obejct from DLL





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


Follow us on Twitter


© 2011 DaniWeb® LLC