我的教授们希望我们不使用像这样的阵列或矢量来起草一份方案:
起草一项方案,利用计算和印刷在停车场停泊的每家 n的停车费。
停车率:
- a parking garage charges a $5.00 minimum fee to park for up to five hours.
- the garage charges an additional $0.50 per hour for each hour or part thereof in the excess of five hours
- the maximum charge for any given 24hr period is $10.00. Assume that no car parks longer that 24 hours at a time.
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 your receipts.
方案产出应如此:
car------Hours------Charge 1--------2.00--------$5.00 2--------5.00--------$5.00 3--------5.30--------$5.50 etc. total: 3---12.30----$15.50
我只设法达到这一目的:
include <iostream>
include <conio.h>
include <cmath>
include <iomanip>
using namespace std;
double calculate(double);
int main()
{
double hours,charge;
int finish;
double sumhours;
sumhours=0;
finish=0;
charge=0;
int cars;
cars=0;
do
{
cout<<"Enter the number of hours the vehicle has been parked: "<<endl;
cin>>hours;
cars++;
sumhours+=hours;
finish=cin.get();
if(hours>24)
{
cout<<"enter a time below 24hrs."<<endl;
cars--;
sumhours=sumhours-hours;
}
}
while(finish!=EOF);
double total=calculate(hours);
cout<<total<<": "<<(cars-1)<<": "<<sumhours;
while(!_kbhit());
return 0;
}
double calculate(double time)
{
double calculate=0;
double fees;
if(time<=5)
return 5;
if(time>15)
return 10;
time=ceil(time);
fees=5+(.5*(time-5));
return calculate;
}