2

基本上我有,

    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)};

我想得到:double studentAverages [STUDENTS]studentAverages=calculateStudentAverages(marks);

使用:

    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;
}

但我得到“无法从'double [5]'转换为'double'”和“无法从'double'转换为'double [5]'”

4

1 回答 1

3

您的错误之一是您的函数被声明为返回一个double,但您试图返回一个doubles. 因此,您要么需要更改函数标题以适应它,要么只返回一个double

与错误无关,但您绝对应该在开始时初始化average0.0否则您在计算中会出现未定义的行为

于 2012-11-08T18:59:10.210 回答