Thread: Student Grade Program

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    8

    Student Grade Program

    Now here's something new. I have created a student grading program that should allow me to enter gades ansd also sort according to date, oldest first. The error code i recieve is:
    line 43 & 44: Expression syntax in function main
    The code is :
    Code:
    * Question 3. It describes a restaurant using structures and arrays to store and print data */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <string.h>
    
    #define N_student 4
    int i,n;
    
    struct student
    {
     char id[5];
     char name[50];
     char dob[10];
     double mark1, mark2, mark3;
     double av_marks;
     char grade;
    } students [N_student];
    
    void assigngrade();
    void printavg();
    
    main()
    {
       char buffer[50];
       double total;
       for (i=0; i<N_student; i++)
       {
    	printf("Enter Student ID no: \n");
     	scanf("%s", students[i].id);
    	printf("Enter Student name: \n");
    	scanf("%S", students[i].name);
    	printf("Enter Date of Birth (dd/mm/yyyy): \n");
    	scanf("%s", students[i].dob);
    	printf("Enter marks obtained for test1: \n");
    	scanf("%d", students[i].mark1);
    	printf("Enter marks obtained for test2: \n");
    	scanf("%d", students[i].mark2);
    	printf("Enter marks obtained for test3: \n");
    	scanf("%d", students[i].mark3);
    	total = double(students[n].mark3)+double(students[n].mark2)+double(students[n].mark1);
    	students[n].av_marks = double(total/3);
    	assigngrade();
       }
    	printf("You've entered the students details. \n");
    
    	printavg();
    
    return 0;
    }
    
    void assigngrade()
    {
        if ((students[n].av_marks<=4) && (students[i].av_marks>3))
    		{
    		students[i].grade='A';
    		}
        else if ((students[i].av_marks<=3) && (students[i].av_marks>2))
    		{
    		students[i].grade='B';
    		}
        else if ((students[i].av_marks<=2) && (students[i].av_marks>1))
    		{
    		students[i].grade='C';
    		}
        else if ((students[i].av_marks<=1)	 && (students[i].av_marks>=0))
    		{
    		students[i].grade='D';
    		}
    }
    
    void printavg()        /* prints the average grade for a student */
    {
    for (i=0; i<N_student; i++)
    {
    
    	printf ("Student Id=");
    	printf ("%s\n",students[i].id);
    	printf ("Student Name=");
    	printf ("%s\n",students[i].name);
    	printf ("Student Average marks=");
    	printf ("%.2f\n",students[i].av_marks);
    	printf ("Student Grade=");					
    	printf ("%c\n",students[i].grade);
    }
    
    }
    What should i do here by right? And what about sorting by date, how would i do that?

  2. #2
    Welcome to the real world
    Join Date
    Feb 2004
    Posts
    50
    Code:
    total = double(students[n].mark3)+double(students[n].mark2)+double(students[n].mark1);
    Unless double is a function, then this code is entirely wrong. If you're trying to type-cast the members of this expression then do:

    Code:
    total = (double)students[n].mark3 + (double)students[n].mark2 + etc
    EDIT: You don't have to type cast because mark1/mark2/mark3 are all double variable types in struct students.
    Last edited by OOPboredom; 05-28-2004 at 07:47 AM.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    8

    Why is the average mark not displayed?

    It's runs after the changes are made but the average mark does not seems to appear. And what about if i want to format it neatly and display results on screen instead of it being bunched up together? How would i sort the students according to date, say oldest first? Some help here please.....

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Unless double is a function, then this code is entirely wrong.
    And if it is a function, it's still entirely wrong, because double is a reserved keyword, and as such, cannot be the name of a function.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Welcome to the real world
    Join Date
    Feb 2004
    Posts
    50
    Bah - Quzah, I actually did say that but an error within the messageboard code must've deleted what I typed

  6. #6
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    attention ....!!!!!!!!!
    Code:
    printf("Enter marks obtained for test1: \n");
    scanf("%d", &students[i].mark1);
    printf("Enter marks obtained for test2: \n");
    scanf("%d", &students[i].mark2);
    printf("Enter marks obtained for test3: \n");
    scanf("%d", &students[i].mark3);
    ------------------------------------take it easy --------------....................enjoy......................

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. grade program code
    By jd7joe in forum C++ Programming
    Replies: 8
    Last Post: 11-18-2005, 04:48 PM
  3. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 11:29 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM