الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

برنامج بحاجة الى تعديل

بدأه rwad2000 في 13 مايو 2009 · 4 رد · 447 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

تحية طيبة للجميع واتمنى الجميع يكون بألف خير

هادا السؤال

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;

}

المشكلة في اللوب الاولى انها ما بتمشي ولا البرنامج بعدها بيمشي

أتمنى الاقي حد يجاوبني و يحللي هاي المشكلة

بأكون شاكر جدا الو ..

كمان ان الخرج من البرنامج لازم يكون بشكل الجدول الي حاولت انفذو في برنامجي

#2

السلام عليكم

لكى يكون الخرج على هيئة جدول يجب استخدام المصفوفات

جرب الكود بعد التعديل

ملحوظه : البرنامج لا يسمح بإدخال ساعات أكبر من 24 ساعه

#include <iostream>
#include <iomanip>
using namespace std;
void header(void);
double calculateCharges(double hours);
int main()
{
double hours[100],charge[100],totalHours=0,totalCharge=0;
int car,i=0;
cout<<"Enter car's number : ";
cin>>car;
while(car>-1)
{
	do {
		cout<<"\nEnter hours park for car ("<<car<<") ";
		cin>>hours;
		if(hours<1.0 || hours>24.0) cout<<" WRONG ENTER  AGAIN!!!\n";
	} while(hours<1 || hours>24);

charge=calculateCharges(hours);
totalHours+=hours;
totalCharge+=charge;
cout<<"Enter car's number : ";
i++;
cin>>car;
}
system("cls");
header();
for(int j=0;j<i;j++)
cout<<"\n"<<setw(10)<<j+1<<setw(8)<<hours[j]<<setw(8)<<charge[j];
cout<<"\n"<<setw(10)<<"Total"<<setw(8)<<totalHours<<setw(10)<<totalCharge<<endl;
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;
if((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;
}

سلام

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#3

مشكور استازي لكني أريد الحل بدون اسنخدام المصفوفات

فهل يمكن السماعدة في ذلك

#4

أخى الكريم

المطلوب من السؤال ثلاث سيارات

يمكنك عمل متغيرات لكل سياره على حده

ثم عرضها فى جدول

سلام

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#5

السلام عليكم

انا نفذت البرنامج من غير لووب وعملت المتغيرات التلاتة وتمام

بس انا كنت بفكر لو في طريقة للحل باستخدام اللوب

شكرا لك

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر ساعة · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…