This is my first C programming class (and its online!)... I'd really appreciate any help you can provide... Here's what's in the book-
Using the student record example in Section 12.2, "Accessing a Member," on page 394, write a function that prints the average for each student in a class. Let an A grade have Value 4, a B grade have value 3, and so forth.
pg 394-
cl_info.h
#Define CLASS_SIZE 100
struct student {
char *last_name;
int student_id;
char grade;
};
**********************
#include "class_info.h"
int main(void)
{
struct student temp, class[CLASS_SIZE];
..........
then it says :
assign values to memebers
temp.grade = 'A'
temp.last_name = "Bushker";
temp.student_id = 590017;
************************
* Here's what I have so far... *
************************
**************Code:cl_info.h #include <stdio.h> #define CLASS_SIZE 100 //CLASS_SIZE is the total number of grade entries struct student { char *last_name; int student_id; char grade; }; *************************** stdt_avg.cpp //Programming in C #include "cl_info.h" void stdt_avg(struct student class[]) { int i = 0; double assignments = 0.0, stdt_total = 0.0; // # of assignments and Total of all grades double stdt_avg = 0.0; // a Students Average Grade curr_student.grade = class[i].grade curr_student.name = class[i].name; curr_student.id = class[i].id; for (i = 0; length > i && ; ++i) { if (strcmp(curr_student, class[i].id)) { switch(class[i].grade) case(class[i].grade == 'A' ) stdt_total+=4; case(class[i].grade == 'B' ) stdt_total+=3; case(class[i].grade == 'C' ) stdt_total+=2; case(class[i].grade == 'D' ) stdt_total+=1; case(class[i].grade == 'F' ) stdt_total+=0; assignments++; stdt_avg = (stdt_total/assignments); printf("%s (Student ID #: %d) average for this class is %f\n", curr_student.name, curr_student.id, stdt_avg); } else { curr_student.name = class[i].name; curr_student.id = class[i].id; stdt_total = grade_value(class[i].grade); assignments = 0; } } printf("\n\n%s", " Grade Scale: 3-4 = A\n" " 2-3 = B\n" " 1-2 = C\n" " 0-1 = D\n"); } int main(void) { struct student class{CLASS_SIZE], *p = &class; (*p)[0].grade = 'B'; // an array pre-filled with various students' grades (*p)[0].last_name = "Seinfeld"; (*p)[0].student_id = 001; (*p)[1].grade = 'A'; (*p)[1].last_name = "Bond"; (*p)[1].student_id = 007; (*p)[2].grade = 'C'; (*p)[2].last_name = "Newman"; (*p)[2].student_id = 003; (*p)[3].grade = 'B'; (*p)[3].last_name = "Seinfeld"; (*p)[3].student_id = 001; (*p)[4].grade = 'B'; (*p)[4].last_name = "Bond"; (*p)[4].student_id = 007; (*p)[5].grade = 'C'; (*p)[5].last_name = "Newman"; (*p)[5].student_id = 003; (*p)[6].grade = 'C'; (*p)[6].last_name = "Seinfeld"; (*p)[6].student_id = 001; (*p)[7].grade = 'C'; (*p)[7].last_name = "Bond"; (*p)[7].student_id = 007; (*p)[8].grade = 'C'; (*p)[8].last_name = "Newman"; (*p)[8].student_id = 003; stdt_avg(class[]); return 0; }
I'm getting errors when I compile due to
'class' missing tag name
and stdt_avg local function definations are illegal
thanks!! cedarcreek