:sad:

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

//Hours and Charges for three cars which parked yesterday
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
 
#include <iomanip>//parameterized stream manipulators
using std::setw;//The output appears in a field width of 10 
using std::setprecision; //sets numeric output precision
 
int main()
{ 
 
 
 double TotalHours,   //using the double to use the variables with decimal points
     a,
     hr1,hr2,hr3,
     charge,
     calculateCharges;
 //Intialization phase
 calculateCharges=0;
 
 //Processing phase
 cout<< "Enter the hours parked for three cars : ";//prompt for input
 cin >> hr1 >> hr2 >> hr3;//input the hour of each of the three cars
 
 cout<< setw(5)<< "Car" << setw(10)<< "Hours" << setw(15)<< "Charges\n\n";  
 cout<<fixed<<setprecision(2);  //sets numeric output precision
 for(int counter=1;counter<=3;counter++) {//loop 3 times and in every loop the counter is incremented by 1
 
  if (counter == 1)
   a = hr1;
  else if  (counter == 2)
   a = hr2;
  else if (counter == 3)
   a = hr3;
 if (a <= 3)
  charge = 2;
  else if (a >19)
   charge = 10;
  else if (a > 3)
   charge = 2 + (a - 3) * (0.5);
 
 
 
  cout <<setw(5) << counter<< setw(10) <<setprecision(2)<< a << setw(10)<< charge <<"\n\n";
 
  calculateCharges+=charge;//in every loop the Sum of the charges is incremented according to the value of the charge
 }
 //Termination phase
 
 TotalHours=hr1+hr2+hr3;//It gives the total of the hours parked for three cars 
 
 cout<<"   "<<"Total"<<setw(7)<<TotalHours<<setw(10)<<calculateCharges<<"\n\n"<<endl;
 
 return 0; //successful termination
}

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

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