2

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]'"

Robᵩ
  • 163,533
  • 20
  • 239
  • 308
  • On which lines are you getting the errors? – Dan F Nov 08 '12 at 18:57
  • You should avoid raw arrays as they [behave strangely](http://stackoverflow.com/a/10253277/365496) – bames53 Nov 08 '12 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 Nov 08 '12 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 http://stackoverflow.com/faq. – ForceMagic Nov 08 '12 at 19:20

1 Answers1

3

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

Dan F
  • 17,654
  • 5
  • 72
  • 110