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

سؤال بسيط؟؟؟ :(

مغلق
بدأه همس الوجدان في 10 أكتوبر 2003 · 2 رد · 636 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
اقتباس
//Exercise#3

//Mail Order House Program

#include <iostream.h>

int main()

{

int product;

int quantity;

double cost=0;

double pr;

cout<<"Enter pairs of item numbers and quantities\n";

cout<<"Enter -1 for the item number to end input: ";

cin>>productcin>>quantity>>quantity;

while (product!= -1){

 

  switch(product){

  case 1:

  pr=2.98;

  break;

  case 2:

  pr=4.50;

  break;

  case 3:

  pr=9.98;

  break;

  case 4:

  pr=4.49;

  break;

  default:

  pr=6.87;

  break;

  }

  cost+=quantity*pr;

  cout<<"Enter pairs of item numbers and quantities\n";

  cout<<" Enter -1 for the item number to end input: ";

  cin>>product>>quantity;

}

cout<<"The total retail value was: "<<cost<<"\n";

return 0;

}

السلام عليكم ورحمة الله وبركاته

كتبت هذا البرنامج... ولكن أحتاج لان أعدله بحيث اذا اخترت القيمة -1 لا يجب أن أدخل ال quantity حتى يعرض ال total

أي كهذه الشاشة مثلا

اقتباس
Enter pairs of item numbers and quantities

Enter -1 for the item number to end input:1 12

Enter pairs of item numbers and quantities

Enter -1 for the item number to end input:2 20

Enter pairs of item numbers and quantities

Enter -1 for the item number to end input:3 88

Enter pairs of item numbers and quantities

Enter -1 for the item number to end input:4 99

Enter pairs of item numbers and quantities

Enter -1 for the item number to end input:5 139

Enter pairs of item numbers and quantities

Enter -1 for the item number to end input:-1

The total retail value was:2403.44

Press any key to continue

أرجو المساعدة والرد بسرعة

ولكم جزيل الشكر

#2

السلام عليكم,

لم أفهم جيدا هدا البرنامج لكن من أجل اقتراحاتك يمكنك تجاوزها كالتالي:

قبل دلك بعض الملاحظات :

في السطر

cin>>productcin>>quantity>>quantity

ف production غير معرفة كما أن quantity معادة مرتين فلا أرى حاجة في هدا التكرار فهما سوف يأخدان دائما القيمة الأخيرة وهنا يجب أن تعيد النظر في هدا حسب ما تريد أن تفعله.

فيما يخص product=-1 لكي تنهي البرنامج يمكن أن تفعل التحويلات التالية :

while (product!= -1) غيرها ب while(1) بما أن 1 يعتبر صحيح ف‘ن هده الحلقة ستبقى دائما شغالة حتى إدا ما أردنا غير دلك

cin>>product>>quantity

السطر الأخير في الحلقة غيره كاتالي :

cin>>product;

if(product == -1)

break;

cin>>quantity;

ندخل قيمة product ونجربها مباشرة فإدا كانت -1 نخرج وفي الحالة الأخرى نعمل كالسابق. ورغم أننا كتبنا cin في سطرين إلا أنه يمكن أن ندخل العددين لثنين في سطر واحد كالسابق.

أتمنى أن هدا يفك مشكلتك وألى اللقاء.

#3

بسم الله الرحمن الرحيم

السلام عليكم

الاخ او الاخت :) همس الوجدان

هذا هو الكود الصحيح للبرنامج الذي عرضته

اقتباس
//Exercise#3

//Mail Order House Program

#include <iostream.h>

int main()

{

int product;

int quantity;

double cost=0;

double pr;

cout<<"To get your total retail value Enter -1 in the Item Number\n";

cout<<"Enter the Item Number: ";

cin>>product;

while (product!= -1)

{

  switch(product)

  {

    case 1:

  pr=2.98;

  break;

    case 2:

  pr=4.50;

  break;

    case 3:

  pr=9.98;

  break;

    case 4:

    pr=4.49;

    break;

    default:

    pr=6.87;

    break;

  }

  cout<<"Enter your Quantity: ";

  cin>>quantity;

  cost+=quantity * pr;

  cout<<"Enter the Item Number: ";

  cin>>product;

}

cout<<"The total retail value was: "<<cost<<"\n";

return 0;

}

ارجو ان يكون هذا هو طلبك

حيث ان نتيجه البرنامج تظهر بهذا الشكل

اقتباس
To get your total retail value Enter -1 in the Item Number

Enter the Item Number: 10

Enter your Quantity: 5

Enter the Item Number: 20

Enter your Quantity: 8

Enter the Item Number: -1

The total retail value was: 89.31

Press any key to continue

ارجو من الله التوفيق و الهدي

هذا الموضوع مغلق.

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