question..

You are required to write a complete C program for a simple grading system. At the beginning of the system, you need to input number of students and number of subjects that have been marked. Then, you need to enter the student's identification number and marks for each subject. While entering the marks, you have to determine their respective grades.

i m new to c programming...at least i have created something as below and need helps...

below is the program that i've created but i have problem to run like this :

enter no of student: which is x
enter no of subject: which is y

enter student id: such as 123
mark for  123 is :

enter mark 1:
grade ?
enter mark 2:
grade ?
enter mark 3:
grade.....

and so on..

total marks:
average mark is:

the problem is i cannot define no of student and subject as what i created...
how to change this to fullfil above format...

#include <stdio.h>



int main()

{

      int count = 0;

      char letter_grade = 'x';

      int a = 0, b = 0, c = 0, d = 0, e = 0;

      int student_ID = 1;

      double test1 = 0.0, test2 = 0.0, final_test = 0.0, semester_average = 0.0, 


      do

      {

            printf("Enter student ID, 0 to terminate: ");

            scanf("%d", &student_ID);



            if(student_ID != 0)

            {

                printf("Enter score #1: ");

                scanf("%lf", &test1);

                printf("Enter score #2: ");

                scanf("%lf", &test2);

                printf("Enter score #3: ");

                scanf("%lf", &final_test);



                printf("%d have the following scores: %lf, %lf and %lf\n", student_ID, test1, test2, final_test);

                semester_average = (0.20*test1) + (0.30*test2) + (0.50*final_test);

                printf("The semester average score for %d is %lf\n", student_ID, semester_average);

                if(semester_average >= 80)

                    { letter_grade = 'A'; a++; }

                else if (semester_average >= 65)

                    { letter_grade = 'B'; b++; }

                else if (semester_average >= 50)

                    { letter_grade = 'C'; c++; }

                else if (semester_average >= 40)

                    { letter_grade = 'D'; d++; }

                else if(semester_average >= 0)

                   { letter_grade = 'E'; e++; }



                printf("The grade for %d is %c\n", student_ID, letter_grade);

                count++;

                printf("Student #: %d\n", count);




      return 0;

}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I suggest you do something like this:

- Create a structure to store each student's information. Maybe call it "Student".
- In the "Student" structure, create another structure for each subject, maybe called "Subject". In there, set up your grade variables or arrays, however you want to set it up.
- Create an array of structures "Student" without specifying an array size (just a pointer is fine)
- Ask the user for number of students
- Ask the user for number of subjects
- Use the malloc() function to dynamically create the exact number of students specified by the user.
- Create a loop that loops through the array of students. In the loop, use the malloc() function to dynamically create the exact number of subjects specified by the user for each student.
- Create a loop per each student, and an inner loop for each subject, and put your code in there, making sure that you access the information inside the structures instead of plain variables.

So something like that will be a good solution for your issue.

thanks for reply..i dont know how to use structure ,array or malloc. i m new to programming...and the worst is i m a distance learner. any other way by just using loop, while or other preprosessor

You don't use preprocessor's to actually program anything. Its commands for the compiler, so I think you used that term incorrectly.

Saying you don't know how to use something and asking for something easier is simply not acceptable in C. Maybe in other languages its fine but C only has a small set of commands to learn, and for that very reason learning how to use them all is an important step towards having "full control" of the language. I highly suggest you learn these things, even if briefly, so you know if its useful for your application or not.

It may seem by the context of your response you don't WANT to learn C. I hope that's not the case. Additionally, you need to know how arrays work for the application you presented, its a fundamental requirement.

Edited 6 Years Ago by N1GHTS: n/a

ok thanks...i will go thru all the fucntions as mentioned above to write the program...well i've done up to do-while statement and loop at the moment...

This article has been dead for over six months. Start a new discussion instead.