Are you trying to get something other than this, which is what I get after fixing those errors?:
D:\prog\foo>g++ -Wall -ansi -pedantic a.cpp -s -o a
D:\prog\foo>a
Student Grade1 Grade2 Grade3 Grade4 Average Standard Dev
________________________________________________________________________________ 1 100 100 100 100 100 100
2 100 0 100 0 50 50
3 82 94 73 86 83 83
4 64 74 84 94 79 79
5 94 84 74 64 79 79
the av is 100
|
BTW, be careful with your "average", which you declare as
int. Here is a change for you:
1 2 3 4 5
|
int grade(int win[5][7]){
float average= 0;
average+=(win[0][1]+win[0][2]+win[0][3]+win[0][4])/4.0;
return average + 0.5;
}
|
Remember to use consistent indentation.
As to your direct question, which I missed: "[how do I put lines 16-39 into grade()?"
Don't. It doesn't belong there.
The grade function should calculate a
single student's grade, and return that to the main function. It should take as argument an array of a single student's grades.
The table of student grades should only contain student grades. If number of marks given so far is important, that should also be an argument to the function, and your grade() function will have to use a loop to calculate the average instead of a single expression.
I have also already spent plenty of time answering this question for one of your classmates:
http://cplusplus.com/forum/general/64906/#msg350962
Your variable names are meaningless. Pick names that mean something. "win" and "table" and "hi" and "wide" don't tell you anything about the data they hold or the function they serve.
Your student grades table should look like this:
1 2 3 4 5 6 7
|
static int NUM_STUDENTS=5;
static int NUM_GRADES=7;
int all_grades[NUM_STUDENTS][NUM_GRADES] = {
{ 90, 97, 85, 12, 99, 79, 82 }, // this student paid attention
{ 19, 4, 23, 88, 47, 0, 26 }, // this student did not
... // etc
};
|
Your grade average function should look like this:
1 2 3 4 5 6 7
|
int average_grade( int grades[], int count ) {
float average=0;
for (...) { // you will have to figure this out yourself
average+=... // this too
}
return (average/count)+0.5;
}
|
Use the function to get a specific student's average grade, call it with that student's grades:
1 2 3
|
cout << "The bad kid's average grade is: ";
cout << average_grade( all_grades[1], NUM_GRADES );
cout << ".\n";
|
You can pick any student the same way:
1 2 3
|
cout << "The good kid's average grade is: ";
cout << average_grade( all_grades[0], NUM_GRADES );
cout << ".\n";
|
If you want to print out a pretty table of grade information, you should put that in its own, different function. That is, a function that calculates the average grade should not be doing anything except calculating the average grade; it should not be
couting anything, etc.
If you do put it in another function, I recommend that you put the type information about the table in the global space like I suggested to your classmate. Using
typedefs is optional.
Hope this helps.