Henry Fox · May 2, 2015 ? calculate the average performance, and grade student for each course, and overall grade.? display the records  in ascending order according to their average performance.? update students’ records.This was my assignment; i've made a code without user defined function because i just wanted a rough workout. I have a problem with my display, as i will show below. Also i would kindly ask assistance on how to make a table to display the info in an orderly fashion. e.g not this100 50 60 5050 60 80 80but100 50 60 50   // they should be alligned well50   60 80 80i wouldve used struct function but i was informed not to use it.here is my code``#includevoid display(){    float  avg[5] ;    char grade[5];    int  mece[5],inte[5],cetg[5],emth[5],code[50], i;    printf("\nThis is the current Student Grades\n");     for ( i = 0 ; i < 5 ; i++ )          printf ( "%d %d %d %d %d %f %c\n",code[i], mece[i], inte[i], cetg[i], emth[i], avg[i], grade[i] );}void edit( ){    char grade[5];     float  avg[5] ;     int  mece[5],inte[5],cetg[5],emth[5],code[50], i,j,a,c,m,nt,g,r,f ;     for ( i = 0 ; i < 5 ; i++ ){            printf ( "\nEnter Student ID, MECE mark, INTE mark,CETG mark, EMTH mark\n" ) ;          scanf ( "%d %d %d %d %d",&code[i], &mece[i], &inte[i], &cetg[i], &emth[i] );        avg[i]=(mece[i]+inte[i]+cetg[i]+emth[i])/4;        if(avg[i]>79){            grade[i]='A';        }        else        if(avg[i]>69){            grade[i]='B';        }        else        if(avg[i]>59){            grade[i]='C';        }        else        if(avg[i]>49){            grade[i]='D';        }        else        if(avg[i]>39){            grade[i]='E';        }        else            grade[i]='F';     }     for (i=0; i < 5; i++)    {        for (j=i+1; j < 5; j++)        {            if (avg[i] < avg[j])            {                a =  avg[i];                avg[i] = avg[j];                avg[j]= a;                c =  code[i];                code[i] = code[j];                code[j]= c;                m =  mece[i];                mece[i] = mece[j];                mece[j]= m;                f =  cetg[i];                cetg[i] = cetg[j];                cetg[j]= f;                g =  emth[i];                emth[i] = emth[j];                emth[j]= g;                nt =  inte[i];                inte[i] = inte[j];                inte[j]= nt;                r =  grade[i];                grade[i] = grade[j];                grade[j]= r;                }        }    }     printf ( "\nStudent Marks\n" ) ;printf("\nThis is your updated Student Grades\n");     for ( i = 0 ; i < 5 ; i++ )          printf ( "%d %d %d %d %d %f %c\n",code[i], mece[i], inte[i], cetg[i], emth[i], avg[i], grade[i] );}void choice(){    int a;    scanf("%d",&a);    switch(a)    {        case 1:display();        break;        case 2:edit();        break;        case 3:printf("Exiting...");        break;        default:printf("You've choosen an unavailable option. Choose The right option.\n");        choice();    }}void main(){    int a; //a is the variable used for option selection.    printf("****Welcome To BIUST Student Grading System Prototype****\n");    printf("\nChoose a number below to perform an operation:\n");    printf("\n1.Display Current Student Grades\n");    printf("2.Update/Edit Student Grades\n");    printf("3.Exit The Program\n");    choice();    getch();}``Here is the updated code:http://textuploader.com/x31rHere is the second update code:http://textuploader.com/x3rg

## Replies

 Henry Fox · May 4, 2015 Thanks for your help zhang yida.I've actually managed to completed the code without any help but when i saw your post it was still quite useful thanx. Franz Schmidt · May 2, 2015 Could you please upload your code on a website likehttp://textuploader.com/and post your link in here.The code tags are messed up and always looses or displays the code wrong. Henry Fox · May 3, 2015 Ok i managed to edit some parts of my code: here is the updated onehttp://textuploader.com/x31ri need my code to redisplay the main() function after edit() function ends;also i'm unable to get my display() function to work; which is supposed to display the student records obtained from the edit() function. Henry Fox · May 3, 2015 Ok i made some major adjustment but i need to make my user defined functions connect. I'm having quite the trouble doing this.Here is my updated code: http://textuploader.com/x3tk``#include#includefloat   avg[5] ;char    grade[5];int     mece[5],inte[5],cetg[5],emth[5],code[50];void display();//function that presents the welcome message and task operationsvoid student(); //function to display grade information of one student selectedvoid overall(); //function to display all the students' grade informationvoid exchange(); //function to swap the storage location for different variablesvoid update(); //function to update current student grade informationvoid choice(); //function for the option selection at welcome screen and other operationsvoid initial(); //function to store default student gradesvoid main(){    initial()    display();    getch();}void display(){    printf("****Welcome To BIUST Student Grading System Prototype****\n");    printf("\n*Please note that default student grade information has already been set up.\n");    printf("Therefore should not be considered as actual student grades.\n");    printf("\nChoose a number below to perform an operation:\n");    printf("\n1.Display An Individuals' grade Information\n");    printf("2.Display All The Students' Grade Information\n");    printf("3.Update Current Student's Grade Information\n");    printf("4.Exit The Program\n");    choice();}void initial(){    int i;avg[i] =100 ;grade[i] ='A';mece[i]=100;inte[i]=100;cetg[i]=100;emth[i]=100;code[i]=13001105;}void choice(){    int a;    scanf("%d",&a);    switch(a)    {        case 1:student();        break;        case 2:overall();        break;        case 3:update();        break;        case 4:printf("Exiting...");        default:printf("You've choosen an unavailable option. Choose The right option.\n");        display();    }}void student(){    int i;    for ( i = 0 ; i < 5 ; i++ )    {        printf("Student %d: %d\n", i,code[i]);    }          printf ( "Enter The Student Number for the corresponding ID to view their grades\n");          printf ( "For Example Enter 3 to view grade information for ID %d", code[3]);          scanf("%d",i);          printf ( "%d\n %d\n %d\n %d\n %d\n %f\n %c\n",code[i], mece[i], inte[i], cetg[i], emth[i], avg[i], grade[i] );}void overall(){    int i;    printf("\nThis is the current Student Grades\n");     for ( i = 0 ; i < 5 ; i++ )          printf ( "%d %d %d %d %d %f %c\n",code[i], mece[i], inte[i], cetg[i], emth[i], avg[i], grade[i] );}void update(){    int   i,j,a,c,m,nt,g,r,f ;    for ( i = 0 ; i < 5 ; i++ ){            printf ( "\nEnter Student ID, MECE mark, INTE mark,CETG mark, EMTH mark\n" ) ;          scanf ( "%d %d %d %d %d",&code[i], &mece[i], &inte[i], &cetg[i], &emth[i] );        avg[i]=(mece[i]+inte[i]+cetg[i]+emth[i])/4;        if(avg[i]>79){            grade[i]='A';        }        else        if(avg[i]>69){            grade[i]='B';        }        else        if(avg[i]>59){            grade[i]='C';        }        else        if(avg[i]>49){            grade[i]='D';        }        else        if(avg[i]>39){            grade[i]='E';        }        else            grade[i]='F';     }     for (i=0; i < 5; i++)    {        for (j=i+1; j < 5; j++)        {            if (avg[i] < avg[j])            {                a =  avg[i];                avg[i] = avg[j];                avg[j]= a;                c =  code[i];                code[i] = code[j];                code[j]= c;                m =  mece[i];                mece[i] = mece[j];                mece[j]= m;                f =  cetg[i];                cetg[i] = cetg[j];                cetg[j]= f;                g =  emth[i];                emth[i] = emth[j];                emth[j]= g;                nt =  inte[i];                inte[i] = inte[j];                inte[j]= nt;                r =  grade[i];                grade[i] = grade[j];                grade[j]= r;                }        }    }     printf ( "\nStudent Marks\n" ) ;printf("\nThis is your updated Student Grades\n");     for ( i = 0 ; i < 5 ; i++ )          printf ( "%d %d %d %d %d %f %c\n",code[i], mece[i], inte[i], cetg[i], emth[i], avg[i], grade[i] );}``I appreciate any help given. zhang yida · May 3, 2015 ok, you want to make a table to display,you can use this:   "\t"   or  use the function : setw();  you can look up how to use this function .it's easy to learn about it.I have some advice to your code. your code exist some problem.first: int the main function,you define a ;    int a; //a is the variable used for option selection.         but you have already define a  in the choice function.so you have no need to do this twice.second: in the edit function,you just use " if else"  to judge the grade , what about avg=80 ,it's more than 79,69,59,49......and in                   fact 80 is suitable for every condition, so you had better use switch and case ,that's more friendly.                  and you also sort the data(am i right?),but after that, the ID and grade are not  the same as begin,the grade of  ID1 is  79 now maybe 39,so you also have to handle with this.above are my advices, my english is not very good,hope it can help youuuuu !!if my answer exist some problem, hope you can tell me,thanks.wish you can deal with it smoothly!!!!!
• 1

## C

130,949 followers