السلام عليكم
تحية طيبة للجميع واتمنى الجميع يكون بألف خير
هادا السؤال
A parking garage charges a $2.00 minimum fee to park for up to 3 hours. The garage charges an additional $0.50 for each hour after 3. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for more than 24 hours.
Calculate and print the parking charges for each of 3 customers who parked their cars in the garage. Print the grand total of all reciepts. Use a seperate function (cacluateCharges) to determine the charge for each customer.
وهادا حل ي
#include <iostream>
#include <iomanip>
using namespace std;
void header(void);
double calculateCharges(double hours);
int main()
{
double hours,charge,totalHours=0,totalCharge=0;
int car;
cout<<"Enter car's number : ";
cin>>car;
while(car!=-1)
{
cout<<"\nEnter hours park for car ("<<car<<") ";
cin>>hours;
cout<<"\nEnter car's number : ";
cin>>car;
charge=calculateCharges(hours);
totalHours+=hours;
totalCharge+=charge;
}
system("cls");
header();
for(int j=1;j<car;j++)
cout<<"\n"<<setw(10)<<j<<setw(8)<<hours<<setw(8)<<charge;
cout<<"\n"<<setw(10)<<"Total"<<setw(8)<<totalHours<<setw(10)<<totalCharge;
system("pause");
return 0;
}
//header function
void header(void)
{
cout<<setw(10)<<"Car"<<setw(8)<<"Hours"<<setw(10)<<"Charge"<<endl;
}
// Calculate Charges function
double calculateCharges(double hours)
{
double charge=0.00;
while(!((hours<1 )|| (hours>24)))
{
if(hours<=3)
charge =2.00;
if(hours>3)
charge=2.00+((hours-3)*0.5);
if (charge>10)
charge=10.00;
}
return charge;
}
المشكلة في اللوب الاولى انها ما بتمشي ولا البرنامج بعدها بيمشي
أتمنى الاقي حد يجاوبني و يحللي هاي المشكلة
بأكون شاكر جدا الو ..
كمان ان الخرج من البرنامج لازم يكون بشكل الجدول الي حاولت انفذو في برنامجي