Write a program parking garage charges and calculate Charges to determine the charge for each customer

Program Parking Garage Charges and Calculate Charges

Write a program parking garage charges and calculate Charges to determine the charge for each customer

Object:
A parking garage charges a $2.00 minimum fee to park 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 tabular format and should calculate and print the total of yesterday’s receipts. The program should use the function calculate Charges to determine the charge for each customer. Your outputs should appear in the following format:

Write a program parking garage charges and calculate Charges to determine the charge for each customer

Code:

#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;

float charges(float hours);

void main()
{
       int cust;
       float one, two, three, hours;
       for(cust=1; cust<=3; cust++)
       {
             cout<<“Enter customer “<<cust<<” parking hours: “;
             cin>>hours;

             if(cust==1)
             {
                   one= hours;
             }
             else if(cust == 2)
             {
                   two= hours;
             }
             else
             {
                   three= hours;
             }
       }
       cout<<endl;
       cout << setw(10)<< left<< “Cars “<< left<< setw(10) << “Hours”<<left<< setw(10)<<“Charges”<<endl;
       cout << setw(10)<< left<< ” 1″<< left<< setw(10) << one<<left<< setw(10)<<charges(one)<<endl;
       cout << setw(10)<< left<< ” 2″<< left<< setw(10) << two<<left<< setw(10)<<charges(two)<<endl;
       cout << setw(10)<< left<< ” 3″<< left<< setw(10) << three<<left<< setw(10)<<charges(three)<<endl;
       cout << setw(10)<< left<< “Total”<< left<< setw(10) << one+two+three<<left<< setw(10)      <<charges(one)+charges(two)+charges(three)<<endl;
       getch();
}
float charges(float hours)
{
       float h=hours;
       float charge= 2.0;
       if(h > 0)
       {
             if(h <= 3)
             {
                   return charge;
             }
             else if(h <= 24)
             while (h >3)
             {
                   charge += 0.5;
                   h–;
                   if(charge >=10)
                   charge=10;
             }
             return charge;
       }
       else
       {
             cout<<“No car parks for longer than 24 hours at a time.”;
       }
}

Output:

Write a program parking garage charges and calculate Charges to determine the charge for each customer

M.A Siddiqui

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

1 Response

  1. June 14, 2020

    […] Write a program parking garage charges and calculate Charges to determine the charge for each custom… […]

Leave a Reply

Your email address will not be published. Required fields are marked *