无法运行此C ++代码?

时间:2015-10-16 19:58:07

标签: c++

我在运行此评分问题时遇到问题,而且我不确定它有什么问题。我对C ++完全陌生,我知道它很糟糕,但任何帮助都会受到赞赏。我在我的班级使用DevC ++,错误一直在第一个括号中返回到getScore,我不知道它有什么问题。

#include <iostream>
using namespace std;

void getScore();
void calcAverage(int s1, int s2, int s3);
int findLowest(int s1, int s2, int s3);
string name;

int main()

{
getScore (int s1, int s2, int s3);


}
void getScore(int s1, int s2, int s3)
{
string name;

cout << "Please enter your name: ";
cin >> name;

cout << "Please enter the grade for test 1: ";
cin >> s1;
cout << "Please enter the grade for test 2: ";
cin >> s2;
cout << "Please enter the grade for test 3: ";
cin >> s3;

calcAverage(s1, s2, s3);

}
void calcAverage(int s1, int s2, int s3)
{

int average;
int lowest; 

lowest = findLowest(s1, s2, s3);

average = ((s1 + s2 + s3) - lowest)/2;

cout << "Congratulations " << name << "!" <<endl;
cout << " " <<endl;
cout << "The average of the two test scores with the lowest dropped is: ";
cout << average << endl;

}
int findLowest(int s1, int s2, int s3)
{

int lowest = s1;

if (lowest > s2)
    lowest = s2;

if (lowest > s3)
    lowest = s3;

return lowest;

}

1 个答案:

答案 0 :(得分:1)

调用函数时,必须传递变量,这些变量在函数调用之前声明。所以你这样打电话给getScore()

void main()
{
    int a = 5, b = 10, c = 15;
    getScore(a, b, c);
}

此外,当您声明函数的原型时,它必须具有与正文实现中相同的参数。