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

لا اعرف اين الخطأ في برنامجي (كود)

مغلق
بدأه qweewq في 28 يناير 2008 · 5 رد · 749 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

الرجاء مساعدتي في معرفة ماهو الخطأ في هذا البرنامج

طبعاً الـ compiler يقول انه يوجد ثلاثة اخطأ وفي الأسطر كذا وكذا وكذا

لكن المشكلة لا اعرف اين يكمن الخطأ بالتحديد

ثم كيف تتم معالجته

(الرجاء التأكد من جميع الـ functions وإستدعاءتها التي هي على شكل مصفوفة array)

وشكرا لكم مقدماً



using namespace std;

void PrintGrade (float []); // first function
void PrintAcademicStatus (float [], int [], int []); // second function
void PrintWarning (float []); // therd function

void main ()
{
int hours_achieved[10], level[10];
long int ID_number[10];
float GPA[10], score[10], academic_status[10];
char name[10][80];

for (int number_of_students=1; number_of_students<=10; number_of_students++)
{
if (number_of_students>=2)
cout << "\nnext student\n";
else;
cout << "enter the name? \n";
cin >> name[number_of_students];
cout << "enter the ID number? \n";
cin >> ID_number[number_of_students];
cout << "enter the GPA? \n";
cin >> GPA[number_of_students];
cout << "enter the hours achieved? \n";
cin >> hours_achieved[number_of_students];
cout << "enter the level? \n";
cin >> level[number_of_students];
cout << "enter the score of programming? \n";
cin >> score[number_of_students];

cout << "this student No. " << number_of_students << " of 10 students";

PrintGrade (score);

PrintAcademicStatus (academic_status, hours_achieved, level);

PrintWarning (GPA);
} //end of the main function


// start of other functions
void PrintGrade (float score2[]) // first function
{
for (int number_of_students=1; number_of_students<=10; number_of_students++)
{

if ((score2[number_of_students]>=90)&&(score2[number_of_students]<=100))
{ if (score2[number_of_students]>=95)
cout << "\nhe got " << 'A' << "+";
else if (score2[number_of_students]<95)
cout << "\nhe got " << 'A';
}
else if ((score2[number_of_students]>=80)&&(score2[number_of_students]<90))
{ if (score2[number_of_students]>=85)
cout << "\nhe got " << 'B' << "+";
else if (score2[number_of_students]<85)
cout << "\nhe got " << 'B';
}
else if ((score2[number_of_students]>=70)&&(score2[number_of_students]<80))
{ if (score2[number_of_students]>=75)
cout << "\nhe got " << 'C' << "+";
else if (score2[number_of_students]<75)
cout << "\nhe got " << 'C';
}
else if ((score2[number_of_students]>=60)&&(score2[number_of_students]<70))
{ if (score2[number_of_students]>=65)
cout << "\nhe got " << 'D' << "+";
else if (score2[number_of_students]<65)
cout << "\nhe got " << 'D';
}
else if ((score2[number_of_students]<60)&&(score2[number_of_students]>=0))
cout << "\nhe got " << 'F';
else if (score2[number_of_students]<0)
cout << "\nplease enter positive score after restart the program";
else
cout << "\nplease enter the score from 0 to 100 after restart the program";
}
}

void PrintAcademicStatus (float academic_status2[],int hours_achieved2[], int level2[]) // second function
{
for (int number_of_students=1; number_of_students<=10; number_of_students++)
{
academic_status2[number_of_students] = (hours_achieved2[number_of_students] / level2[number_of_students]); // mathematical expression

if (academic_status2[number_of_students]>=16) // the 16 is the average number of hours achieved in level
cout << "\nacademic status: a regular student";
else if (academic_status2[number_of_students]<16)
cout << "\nacademic status: a unregular student";
else
cout << "\nenter your hours achieved and your level correctly";
}
}

void PrintWarning (float GPA2[]) // therd function
{
for (int number_of_students=1; number_of_students<=10; number_of_students++)
{
if ((GPA2[number_of_students]<=4)&&(GPA2[number_of_students]>=1))
cout << "\nhe don't have any academic warning \n";
else if ((GPA2[number_of_students]<1)&&(GPA2[number_of_students]>=0))
cout << "\nhe have one or more of academic warnings \n";
}
}
	 # include <iostream>

#2

بعد نظرة سريعة على الكود..

الخطأ هو أنك لم تغلق الدالة الرئيسية main ..

ملاحظات:

حاول تستخدم خاصية الـswitch بدل الإستخدام المتكرر لـif else .. لأن هذا سيعطي مظهر أفضل للكود وتكون قرائته أوضح بكثير.

يفضل أن تجعل أسماء المتغيرات أصغير يعني مثلاُ بدل ماتستخدم hours_achieved إستخدم hours فقط و بدل number_of_students إستخدم count

وكذلك أنا ألقيت نظرة على دالة PrintWarning وغيرت فيها ورتبها بشكل بسيط.. لاحظ شكلها كذا أفضل وأبسط بكثير..

هذه هي الدالة سابقاً

	void PrintWarning (float GPA2[]) // therd function
	{
	for (int number_of_students=1; number_of_students<=10; number_of_students++)
	{
	if ((GPA2[number_of_students]<=4)&&(GPA2[number_of_students]>=1))
   cout << "\nhe don't have any academic warning \n";
	else if ((GPA2[number_of_students]<1)&&(GPA2[number_of_students]>=0))
   cout << "\nhe have one or more of academic warnings \n";
	}
	}

وهذه هي الدالة بعد التعديل

	void PrintWarning (float GPA2[]) // therd function
	{
		for (int i = 1; i <= 10; i++)
		{
			if (GPA2[count] < 1 && GPA2[count] >= 0)
				cout << "\nhe have one or more of academic warnings \n";
			else
				cout << "\nhe don't have any academic warning \n";
		}
	}

لاحظ أنني جعلت الشرط if شرط واحد.. فكر فيها وراح تفهم السبب. وكذلك إستخدمت المتغير (i) بدل إسم المتغير number_of_students لأن المقصود من الـloop هو التكرار عشر مرات (أي لا يوجد سبب لإستخدام المتغيرnumber_of_students )..

وكذلك أنت تستدعي دوال الطباعة من داخل الـloop الذي في الدالة الرئيسية وأيضاً تعمل loop في نفس الدوال وكذا راح تكرر الطباعة أكثر من المطلوب (فهمت الخطأ!)..

وأيضاً في الـ بداية البرنامج وضعت وضعت الشرط

   if (number_of_students>=2)
  cout << "\nnext student\n";

الذي فهمته أنه عندما يدخل المستخدم معلومات الطالب الأول يطبع البرنامج .. next student إذا كل ماعليك فعله هو ان تضع الطباعة بعد كل أوامر إدخال البيانات (في نهاية الـloop).

تم تعديل هذه المشاركة بواسطة m4design في 28 يناير 2008 في 04:55

#3

لم أطلع على الكود ، لكن رجاءًا... من يضع سؤال كهذا أن يختصر علينا نصف الطريق وذلك بوضع رسالة الخطأ..

في فيجيوال استوديو إضغط بزر اليمين على الرسالة واختر نسخ، ثم الصقها...

وشكرًا..

أرجو أن سكون الحل في كلام أخي m4design.

سلام

#4

السلام عليكم :

الكود الخطاء فقط عندك في تقفيل قوس الفور.

for (int number_of_students=1; number_of_students<=10; number_of_students++)
{

القوس لم يقفل.

تم تعديل هذه المشاركة بواسطة arabi2013 في 28 يناير 2008 في 11:02

tvquran_6.gif

#5

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

ما شاء الله عليك يا arabi2013 فعلا قوس فور هو اللي مسبب المشكلة

(والله جلست اكثر من ساعة على معرفة الخطأ فقط ولم اجده مع وجود قائمة الأخطاء)

بصراحه اللسان يعجز عن شكرك

وإذا تبغى خدمه في اي اي اي شيء لا تتردد ابداً ............ ولا تنسى اننا في مدينه وحده

اخوك هيثم

تم تعديل هذه المشاركة بواسطة qweewq في 29 يناير 2008 في 00:53

#6

حياك الله ياهيثم . ولا شكر على واجب

فقط لاتنساني من الدعاء وفقك الله.

tvquran_6.gif

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

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

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

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

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

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