Okay i am pulling my hair out. I am trying to get this program using the two files class_info.h and my main file to get the students averages to print out.
Where am i missing the boat in my program to get it to call the function and work. Right now it just says press any key to continue.
This structure stuff is hard to understand.
Please help me.
in class_info.h file
Code:#define CLASS_SIZE 100 struct student{ char *last_name; int student_id; char grade; };
in main here is what i have:
Code:#include "class_info.h" #include <stdio.h> void student_average(struct 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 average for each student by student id is %c\n", id); printf("The average for the class is %f.\n", average); } } 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; student_average; return 0; }



LinkBack URL
About LinkBacks


