PLZ help me !!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 1
Reputation: takayuki is an unknown quantity at this point 
Solved Threads: 0
takayuki takayuki is offline Offline
Newbie Poster

PLZ help me !!

 
0
  #1
May 27th, 2006


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


  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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,678
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 263
Lerner Lerner is offline Offline
Posting Virtuoso

Re: PLZ help me !!

 
0
  #2
May 27th, 2006
Have you tried changing the paremeter for setprecision to see how it affects the output?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: PLZ help me !!

 
0
  #3
May 27th, 2006
Remove fixed.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC