المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Whats wrong ?!



Darkseeker
11-04-2004, 09:17 AM
#include <stdio.h>
int main()
{
int grade;
int aCount = 0 , bCount = 0, cCount = 0, dCount = 0, fCount = 0;

printf("Enter a letter for the grades :\n");
printf("Enter EOF To end the opration\n");

while ( ( grade = getchar() ) != EOF )
{
switch ( grade )
{
case 'A': case 'a':
++aCount;
break;
case 'B': case 'b' :
++bCount;
break;
case 'C' : case 'c':
++cCount;
break;
case 'D' : case 'd' :
++dCount;
break;
case 'F' : case 'f' :
++fCount;

break;
default:

printf("Incorrect letter grade entered\n");
printf("Enter a new grade \n");
break;
}
}

printf( "\nTotals for each letter grade are:\n" );
printf("A: %d\n",aCount);
printf("B: %d\n",bCount);
printf("C: %d\n",cCount);
printf("D: %d\n",dCount);
printf("F: %d\n",fCount);
return 0;
}

Whats Wrong Now Guys :31:

Arsene Lupin
11-04-2004, 09:55 AM
انت معرف grade على انه int.. و بعدين تستخدمه على انه char... ما يصلح

انا ما ادري عن فنكشن getgrade وش ترجع... لكن اذا كانت ترجع حرف فالمفروض تعرف grade باستخدام char

و نقطه ثانيه هي كلمة EOF... لو بتستخدم char... المتغير ما يقدر يشيل اكثر من حرف على حسب علمي... لازم تستخدم string عشان تقدر تشيل كلمة. فالأفضل لك انك تبدل كلمة EOF ب X او شي من هالقبيل... اهم شي يكون حرف واحد.

hope that helps!

Darkseeker
11-04-2004, 04:31 PM
انت معرف grade على انه int.. و بعدين تستخدمه على انه char... ما يصلح

انا ما ادري عن فنكشن getgrade وش ترجع... لكن اذا كانت ترجع حرف فالمفروض تعرف grade باستخدام char

و نقطه ثانيه هي كلمة EOF... لو بتستخدم char... المتغير ما يقدر يشيل اكثر من حرف على حسب علمي... لازم تستخدم string عشان تقدر تشيل كلمة. فالأفضل لك انك تبدل كلمة EOF ب X او شي من هالقبيل... اهم شي يكون حرف واحد.

hope that helps!

it worked thx ^^
but what about this one

#include <stdio.h>

#define TAX 0.0825


int main()
{
int meal_price, sales_tax, amt_tendered, change, grand_total, total;
int num_customers, response;

grand_total = 0.0;
num_customers = 0;

printf("\n\n*** C-Side Restaurant***\n\n");
printf("\n\nDo you want to process a customer ?");
printf("\n\nEnter 1 for yes 0 for no : \n");
scanf("%d",&response);

while ( response == 1 )

{
printf("\n\nEnter the price of the meal : $");
scanf("%1f",&meal_price);
printf("\n\n");

sales_tax = meal_price * TAX;
total = meal_price + sales_tax;

printf("\nPrice of meal : %6.2f",meal_price);
printf("\nSales Tax : %6.2f",sales_tax);
printf("\n-------------------\n");
printf("\nThe Total Amount: %6.2f\n\n",total);

printf("\nEnter Amount Tendered : $");
scanf("%1f",&amt_tendered);
printf("\n\n");

change = amt_tendered - total;

printf("\n Amount Tendered : $ %6.2f",amt_tendered);
printf("\n Total Amount : $ %6.2f ",total);
printf("\n-------------------");
printf("Change : $ %6.2f",change);


++num_customers;
grand_total += total;


printf("\n\nDo you want to process a customer ?");
printf("\n\nEnter 1 for yes 0 for no");
scanf("%d",&response);

}

printf("\n\nGrand Totals : ");
printf("\n\n Total Customers : %d",num_customers);
printf("\n\n Total Receipts : %.2f\n\n",grand_total);

return 0;
}


:31:

Arsene Lupin
12-04-2004, 11:27 AM
صراحه انا متعلم على ال C++... يعني ما اعرف بالظبط اسلوب استخدام printf و scanf


لكن نفرض انه سليم... ايش بالظبط المشلكه في البرنامج؟... هل المشكله في ان البرنامج ما يسوي الي مطلوب منه؟ او البرنامج من اصله فيه اخطاء عند ال compile؟

عموما جرب تعدل في تعريف التاكس عندك اذا ما كنت متأكد من طريقتك.

استخدم:

;int const TAX = 0.0825

او عرفها عادي جوا ال main و متى ما زبط البرنامج جرب تحطها برا.


نصيحه : حاول تستخدم علامات الكومينتس عشان تشرح البرنامج الي تشتغل عليه... لأنه ممكن ترجع بعد فتره تكون ناسي وش المفروض يسوي البرنامج في مكان معين. و راح تفيدك جدا اذا خليتها عاده في كتابة برامج طويله.

قناص نجد
14-04-2004, 08:03 PM
السلام عليكم ..

اخ black wolf .. اطلعت على كود البرنامج تبعك ووضبطته لك وبأعلمك الاخطاء الي طحت فيها ..

اولا .. انت عرفت المتغيرات ( meal_price, sales_tax, amt_tendered, change, grand_total, total ) من نوع "int" وانت جالس تتعامل معها كــ " float "

ثانيا .. اذا قراءت قراءة متغير من نوع " float " يجب ان تستعمل ( f% ) دون وضع اي رقم مثل ما فعلت انت scanf("%1f",&meal_price);

وضع الارقام بعد علامة الـ ( % ) يكون في الـ printf فقط ..


وهذا الملف الذي عدلت فيه سأقوم بأرفاقه ..
وأرجو اكون افدتك :)

-----------------------------------------------------------

/* ---------------- ( SNIPER ) -------------------*/


#include <stdio.h>

#define TAX 0.0825


int main()
{
float sales_tax, amt_tendered,meal_price, change, grand_total, total;
int num_customers, response;


grand_total = 0.0;
num_customers = 0;

printf("\n\n*** C-Side Restaurant***\n\n");
printf("\n\nDo you want to process a customer ?");
printf("\n\nEnter 1 for yes 0 for no : \n");
scanf("%d",&response);

while ( response == 1 )

{
printf("\n\nEnter the price of the meal : $");
scanf("%f",&meal_price);
printf("\n\n");

sales_tax = meal_price * TAX;
total = meal_price + sales_tax;

printf("\nPrice of meal : %6.2f",meal_price);
printf("\nSales Tax : %6.2f",sales_tax);
printf("\n-------------------\n");
printf("\nThe Total Amount: %6.2f\n\n",total);

printf("\nEnter Amount Tendered : $");
scanf("%f",&amt_tendered);
printf("\n\n");

change = amt_tendered - total;

printf("\n Amount Tendered : $ %6.2f",amt_tendered);
printf("\n Total Amount : $ %6.2f ",total);
printf("\n-------------------");
printf("Change : $ %6.2f",change);


++num_customers;
grand_total += total;


printf("\n\nDo you want to process a customer ?");
printf("\n\nEnter 1 for yes 0 for no");
scanf("%d",&response);

}

printf("\n\nGrand Totals : ");
printf("\n\n Total Customers : %d",num_customers);
printf("\n\n Total Receipts : %.2f\n\n",grand_total);

return 0;
}


/* ---------------- ( SNIPER ) -------------------*/