错误:控制到达非无效功能的末尾.找不到修复错误的位置

Error: Control reaches end of non-void function. Cant find where to fix the error

本文关键字:错误 位置 找不到 功能 控制 无效      更新时间:2023-10-16

我找不到错误,错误位于函数(计算查找计算)中。

这就是代码似乎有问题的地方。

开始

calculation findCalculations(float A[][5], int rows) {
    {
        double sum = 0;
        for (int x = 0; x < rows; x++) {
            cout << endl;
            for (int y = 0; y < 5; y++) {
                sum = sum + A[x][y];
            }
        }
        cout << "Average graylevel: " << sum << endl;
        double min = 0;
        for (int x = 0; x < rows; x++) {
            for (int y = 0; y < 5; y++) {
                if (A[x][y] < min) {
                    min = A[x][y];
                }
            }
        }
        cout << "Min graylevel: " << min << endl;
        int graylevel = 0;
        for (int x = 0; x < rows; x++) {
            for (int y = 0; y < 5; y++) {
                if (A[x][y] >= .75) {
                    graylevel = A[x][y];
                }
            }
            cout << "Number of bright pixels: " << graylevel << endl;
        }
        bool bright = true;
        bool dark = false;
        for (int x = 0; x < rows; x++) {
            for (int y = 0; y < 5; y++) {
                if (A[x][y] < .5) {
                    bright = A[x][y];
                }
                if (A[x][y] >= .5) {
                    dark = A[x][y];
                }
            }
            if (dark < bright) {
                cout << "Image has more bright pixels: yes" << endl;
            } else if (dark == bright) {
                cout << "Image has more bright pixels: they have the same" << endl;
            } else {
                cout << "Image has more bright pixels: no" << endl;
            }
        }
    }
}

如果有人可以帮助我找出出了什么问题,那将意味着非常感谢。

你在函数签名中告诉编译器

calculation findCalculations(float A[][5], int rows)

该函数正在返回一个calculation对象。但是你的函数中没有实际这样做的 return 语句。你只是通过cout输出东西.如果您实际上不需要从函数返回任何内容,则应将函数签名更改为

void findCalculations(float A[][5], int rows)

向编译器指示这一点。如果调用此函数的代码实际上需要calculation对象,则必须通过 return 语句在函数中的某个位置创建并返回它们。