0

我似乎无法编译我的代码 - 这是我得到的错误:

6\problem11.cpp(21):错误 C2660:'calcScore':函数不接受 0 个参数

解决这个问题有什么帮助或建议吗?这是一个家庭作业问题,我似乎无法弄清楚如何解决该错误。我们目前还不允许使用数组。

#include <iostream>

using namespace std;

void getJudgeData(int);
void calcScore(float, float, float, float, float);
float findHighest(float, float, float, float, float);
float findLowest(float, float, float, float, float);

    int main()
    {
        getJudgeData(1);
        getJudgeData(2);
        getJudgeData(3);
        getJudgeData(4);
        getJudgeData(5);
        calcScore();

        system("pause");
        return 0;
    }

    void getJudgeData(int jnumber)
{
    float score1, score2, score3, score4, score5;

    switch(jnumber)
    {
        case 1: cout << "\nEnter the score for judge " << jnumber << ". ";
                cin >> score1;
                break;
        case 2: cout << "\nEnter the score for judge " << jnumber << ". ";
                cin >> score2;
                break;
        case 3: cout << "\nEnter the score for judge " << jnumber << ". ";
                cin >> score3;
                break;
        case 4: cout << "\nEnter the score for judge " << jnumber << ". ";
                cin >> score4;
                break;
        case 5: cout << "\nEnter the score for judge " << jnumber << ". ";
                cin >> score5;
                break;
                calcScore(score1, score2, score3, score4, score5);
    }
}

void calcScore(float one, float two, float three, float four, float five)
{
    float high, low, avg;

        high = findHighest(one, two, three, four, five);
        low = findLowest(one, two, three, four, five);

        avg = ((one + two + three + four + five) - (high+low))/3;

        cout << "Final score is: " << avg <<endl;
        return;
}

float findHighest(float high1, float high2, float high3, float high4, float high5) // find highest score 
{
    float high = 10;

        if (high1 > high)
        {
             high1 = high;
        }
        else if ( high2 > high)
        {
             high2 = high;
        }
        else if ( high3 > high)
        {
             high3 = high;
        }
        else if (high4 > high)
        {
             high4 = high;
        }
        else if ( high5 > high)
        {
             high5 =  high;
        }

        return  high;
}

float findLowest (float low1, float low2, float low3, float low4, float low5) // find lowest score
{
    float low = 1;

        if (low1 < low)
        {
            low1 = low;
        }
        else if (low2 < low)
        {
            low2 = low;
        }
        else if (low3 < low)
        {
            low3 = low;
        }
        else if (low4 < low)
        {
            low4 = low;
        }
        else if (low5 < low)
        {
            low5 = low;
        }

        return low;
}
4

2 回答 2

2

你有线

calcScore();

但是该函数需要参数(在其余代码中声明和定义)。

添加论据!

于 2013-03-07T01:06:38.050 回答
1
calcScore();

正如编译器所说,你不能这样做,因为函数需要 4 个参数。

让我看看我是否明白你想要做什么。进行这些更改

float getJudgeData(int jnumber) //return the score
{
    float score; // only one score neeeded

    ...
    //calcScore(score1, score2, score3, score4, score5);
}

您可以删除最后calcScore一行,因为

a) 无论如何都不会到达它,它是在 switch 内的 break 语句之后。
b) 此时您将获得一个分数。

int main()
{
    float score1, score2, score3, score4, score5;
    score1=getJudgeData(1);
    score2=getJudgeData(2);
    score3=getJudgeData(3);
    score4=getJudgeData(4);
    score5=getJudgeData(5);
    calcScore(score1, score2, score3, score4, score5);
    ...
}

这可能只是做你想做的 - 获取每个浮点数,然后调用calcScore它们。

于 2013-03-07T01:06:53.963 回答