I'm writing a program which calculates the average of several students' test grades. Whenever I run it only the last students' average is displayed.
For example, if this is my input:
Student 1
Test 1: 90
Test 2: 90
Test 3: 100
Test 4: 100
Student 1
Test 1: 94
Test 2: 90
Test 3: 91
Test 4: 89
Student 3
Test 1: 64
Test 2: 67
Test 3: 66
Test 4: 63
Seems to be some confusion ing your getAverage function. double is used for declarations, definitions and parameters, not as an arguments or expressions. Also, no need for the second loop.
Your original getAverage function calculates the averages for each student correctly, but stores each calculation in the same variable. The result of each calculation overwrites the previous result.
dacheeba's function, by contrast, accesses outside the boundaries of the grades array resulting in undefined behavior (and botches the calculation to boot.)
I would suggest something more along the lines of:
double getAverage(int grades[][4], unsigned studentIndex) where studentIndex is the index of the student who's grades you want to average.
Then, the function might look something like this:
1 2 3 4 5 6 7 8 9
double getAverage(int grades[][4], unsigned index)
{
int sum = 0;
for ( unsigned i=0; i<4; ++i )
sum += grades[index][i] ;
return sum / 4.0 ;
}