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

خطأ في if statement

بدأه لسان الدهر في 29 ديسمبر 2010 · 5 رد · 765 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ...

طلب منا الاستاذ هذا البروجكت..

Write a C program to read results of class of 20 students. Each student has 4 results, distributed as follow:

• Test 1 25 %

• Test 2 25 %

• Test 3 25 %

• Final 50 %

The program should do the following tasks

1- Read the 4 results of each student.

2- Store the results in separated single dimensional arrays.

3- Create new array Average; which contains the average of each student. (see point 4)

4- The average of student is determined by user-defined function named as calculate_average; which receives the four results and returns the average of the - final and the highest two tests only- (drop the lowest test).

5- Create a new array Grades; which contains the equivalent grade letter for each student. (see point 6)

6- The grade letter must be determined using a user-defined function named as grade_letter that receives the average of each student and returns the corresponding letter based on the following categories.

100 – 90 is A

89 – 80 is B

79 – 70 is C

69 – 60 is D

59 – 0 is F

وهذه محاولتي لحل أول جزء من الكود لكني لم أوفق !!

فأتمنى منكم مساعدتي لأعرف ما هو الخطأ في if statment

#include<stdio.h>
#define STUDENTS 2
int
main()
{
	double test1,test2, test3, test4;
	int student_num=1;

	while(student_num <= STUDENTS)
	{
     printf("enter the score for student %d\n",student_num);

       printf("enter the score in test 1>> ");
		   scanf("%lf",&test1);
		    printf("enter the score in test 2>> ");
		   scanf("%lf",&test2);
		    printf("enter the score in test 3>> ");
		   scanf("%lf",&test3);
		    printf("enter the score in test 4>> ");
		   scanf("%lf",&test4);
		    printf("\n\n");
		student_num=student_num+1;

     	 if (test1<0 || test1>25 || test2<0 || test2>25 || test3<0 || test3>25 || test4<0 || test4>50 ){
		   printf("invaled value\n");

		printf("enter the scoer again\n");
		     printf("enter the score for student %d\n",student_num);

       printf("enter the score in test 1>> ");
		   scanf("%lf",&test1);
		    printf("enter the score in test 2>> ");
		   scanf("%lf",&test2);
		    printf("enter the score in test 3>> ");
		   scanf("%lf",&test3);
		    printf("enter the score in test 4>> ");
		   scanf("%lf",&test4);
		   printf("\n\n");}

		   else 
			   printf("go to next student");

	}







	return (0);

}

وإذا عندكم أي ملاحظات أو hints تمكنني من استكمال كتابة الكود سأكون شاكرة لكم...

شكــــراً جزيلاً مقدماً

#2

و عليكم السلام ...

أخي المشكلة لديك هي أنك تقوم بزيادة student_num قبل التأكد من صحة المعطيات ، جرب هذا الكود بعد التعديل ...

#include<stdio.h>
#define STUDENTS 2			/* this should be changed to 20 according to the question */
int
main()
{
        double test1,test2, test3, test4;
        int student_num=1;

        while(student_num <= STUDENTS)		/* you could simply put "student_num <= 20" */
        {
			printf("enter the score for student %d\n",student_num);

			printf("enter the score in test 1>> ");
            scanf("%lf",&test1);
            printf("enter the score in test 2>> ");

            scanf("%lf",&test2);
			printf("enter the score in test 3>> ");
			scanf("%lf",&test3);
			printf("enter the score in test 4>> ");
			scanf("%lf",&test4);
			printf("\n\n");


			if (test1<0 || test1>25 || test2<0 || test2>25 || test3<0 || test3>25 || test4<0 || test4>50 )
			{
				printf("invaled value\n");

                printf("enter the score again\n");
                     printf("enter the score for student %d\n",student_num);

				printf("enter the score in test 1>> ");
                   scanf("%lf",&test1);
                    printf("enter the score in test 2>> ");
                   scanf("%lf",&test2);
                    printf("enter the score in test 3>> ");
                   scanf("%lf",&test3);
                    printf("enter the score in test 4>> ");
                   scanf("%lf",&test4);
                   printf("\n\n");
             }

                   else 
                           printf("go to next student");

                         student_num=student_num+1;

        }







        return (0);

}

تم تعديل هذه المشاركة بواسطة hamany-pirlo في 29 ديسمبر 2010 في 21:54

Program every day for 20 years and you will become a good programmer. Program every day for 10 years and study algorithms on the side and you will become a great programmer !

على الأقل هذا اللي سمعته ...

#3

السلام عليكم

ممكن احد يفهمني باجي الاسئله :mellow:

شو المطلوب منه

#4

حاولت اكمل بس ما ا عرف شو الغلط ؟؟؟

:unsure:

Cpp1.cpp

#5
2011 كتب:

السلام عليكم

ممكن احد يفهمني باجي الاسئله :mellow:

شو المطلوب منه

حسناً.

2 : يجب عليك في كل مرة تقوم بها بقراءة نتائج الإختبارات لطالب أن تقوم بتخزين هذه النتائج في مصفوفة ذو حجم 4*1.

3 : قم بإنشاء مصفوفة بحجم 20*1 بحيث تحتوي على متوسط الدرجات لكل طالب.

4 : قم بإنشاء دالة بإسم calculate_average حيث تقوم هذه الدالة بأخذ نتائج الإختبارات لطالب و من ثم تقوم بحساب و إرجاع متوسط هذه الإختبارات (لا يدخل في حساب المتوسط الأقل من الإختبارات test1, test2, test3).

5 : قم بإنشاء مصفوفة بحجم 20*1 من نوع char تحتوي على الدرجة النهائية لكل طالب.

6 : قم بإنشاء دالة باسم grade_letter بحيث تقوم بأخذ متوسط الدرجة لكل طالب ، و تقوم بإرجاع الدرجة النهائية للطالب (A,B, ...).

Program every day for 20 years and you will become a good programmer. Program every day for 10 years and study algorithms on the side and you will become a great programmer !

على الأقل هذا اللي سمعته ...

#6

شـــــكراً جزيلاً على المساعدة...

جربت الكود واشتغل

:)

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