Here is the lastest version. Still compiles good. Doesnt print student average. does my first fuction,,, average for class , but not the student one.
Please help. I indented the code as requested. sorry for the mess.
in class_info.h file
Code:
#define CLASS_SIZE 100
struct student{
char *last_name;
int student_id;
char grade;
};
Code:
#include <stdio.h>
void average(struct student total[], int length);
void student_average(struct student total[],int ,int);
int main(void)
{
struct student total[CLASS_SIZE];
total[0].grade = 'A';
total[0].last_name = "Bushker";
total[0].student_id = 000001;
total[1].grade = 'B';
total[1].last_name = "johnson";
total[1].student_id = 000002;
total[2].grade = 'C';
total[2].last_name = "Smith";
total[2].student_id = 000003;
total[3].grade = 'A';
total[3].last_name = "Taylor";
total[3].student_id = 000004;
total[4].grade = 'B';
total[4].last_name = "Ross";
total[4].student_id = 000005;
total[5].grade = 'A';
total[5].last_name = "Ross";
total[5].student_id = 000005;
average( total, 6 );
student_average(total, 5, 2 );
return 0;
}
void average(student total[], int length)
{
double sum=0.0,avg;
int i;
for( i=0;i<length;++i )
{
if( total[i].grade == 'A' )
sum+=4;
if( total[i].grade == 'B' )
sum+=3;
if( total[i].grade == 'C' )
sum+=2;
if( total[i].grade == 'D' )
sum+=1;
if( total[i].grade == 'F' )
sum+=0;
}
avg = (sum/length);
printf("The average for the class is %f.\n", avg);
}
void student_average(student total[], int length, int id)
{
float sum;
float average;
int grade_count;
grade_count=0;
sum=0;
int index=0;
average=0.0;
for (int k=0 ; k<length;k++)
{
if (total[k].student_id==id)
{
grade_count++;
if( total[k].grade == 'A' )
sum+=4;
if( total[k].grade == 'B' )
sum+=3;
if( total[k].grade == 'C' )
sum+=2;
if( total[k].grade == 'D' )
sum+=1;
if( total[k].grade == 'F' )
sum+=0;
}
}
average=(sum/grade_count);
for (int l=0 ; l<length;l++)
{
if (total[l].student_id==id)
{
index=l;
break;
}
}
printf("The student id, last name, and average is: %f%S%f.\n", id, average);
}