Basically I have,
double marks [STUDENTS][ASSIGNMENTS] = { (0.1,0.2,0.3,0.4,0.5,0.6,0.7),
(1,0.9,0.8,0.7,0.6,0.5,0.5),
(0.8,0.8,0.8,0.8,0.8,0.8,0.8),
(0.8,0.9,0.7,0.8,0.9,0.7,0.8),
(0.5,0.6,0.7,0.8,0.9,0.5,0.9)};
And I want to get: double studentAverages [STUDENTS] from studentAverages=calculateStudentAverages(marks);
Using:
double calculateStudentAverages (double marks[STUDENTS][ASSIGNMENTS]){
double averages[STUDENTS];
double average;
for (int i = 0; i < STUDENTS; i++) {
for (int j = 0; j < ASSIGNMENTS; j++) {
average = average + marks[i][j];
}
averages[i]=average/ASSIGNMENTS;
}
return averages;
}
But I get "cannot convert from 'double [5]' to 'double'" and "cannot convert from 'double' to 'double [5]'"
-
On which lines are you getting the errors?Dan F– Dan F2012年11月08日 18:57:40 +00:00Commented Nov 8, 2012 at 18:57
-
You should avoid raw arrays as they behave strangelybames53– bames532012年11月08日 19:04:33 +00:00Commented Nov 8, 2012 at 19:04
-
The line where the function is called I get: '=' : cannot convert from 'double' to 'double [5]' The return line in the functions gives: 'return' : cannot convert from 'double [5]' to 'double'user1810269– user18102692012年11月08日 19:08:00 +00:00Commented Nov 8, 2012 at 19:08
-
Welcome on SO. Did you know that you can edit your own question to modify or add more information? Please have a look to our FAQ as well stackoverflow.com/faq.ForceMagic– ForceMagic2012年11月08日 19:20:35 +00:00Commented Nov 8, 2012 at 19:20
1 Answer 1
One of your errors is from the fact that your function is declared to return a single double but you are attempting to return an array of doubles. So you either need to change your function heading to accomodate for that, or only return one double
Not related to the errors, but you should definitely initialize average to 0.0 when you start, otherwise you have undefined behavior in the calculation
5 Comments
averages can't really be returned from the function because they are local