This is where I get error:
calcScore(double score1,double score2, double score3, double score4, double score5);
这是我的代码,我不知道如何修复错误;我不确定错误是什么意思。我试过看教科书和网上的例子,但我仍然感到困惑;这是我们必须使用函数
的第一个任务#include <iostream>
using namespace std;
void getJudgesData();
void calcScore();
int main()
{
double scoreAverage=-9;
double score1=-9.0;
double score2=-9.0;
double score3=-9.0;
double score4=-9.0;
double score5=-9.0;
getJudgesData();
calcScore(double score1,double score2, double score3, double score4, double score5);
return 0;
}
// getJudgesData Program
void getJudgesData(double &score1, double &score2, double &score3, double &score4, double &score5)
{
do
{
cout << "Enter judges score: ";
cin >> score1;
do
{
if (score1 < 0 || score1 >10)
{
cout << "Score has to range from 0-10 \n";
cout << "Please enter a valid score: ";
cin >> score1;
}
}while (score1<0 || score1 >10);
}
while (score1<0 || score1 >10);
do
{
cout << "Enter judges score: ";
cin >> score2;
do
{
if (score2 < 0 || score2 >10)
{
cout << "Score has to range from 0-10 \n";
cout<< "Please enter a valid score: ";
cin >> score2;
}
}while (score2 <0 || score2 >10);
}
while (score2<0 || score2 >10);
do
{
cout << "Enter judges score: ";
cin >> score3;
do
{
if (score3 < 0 || score3 >10)
{
cout << "Score has to range from 0-10 \n";
cout << "Please enter a valid score: ";
cin >> score3;
}
}while (score3 < 0 || score3 >10);
}
while (score3<0 || score3 >10);
do
{
cout << "Enter judges score: ";
cin >> score4;
do
{
if (score4 < 0 || score4 >10)
{
cout << "Score has to range from 0-10 \n";
cout << "Please enter a valid score: ";
cin >> score4;
}
}while (score4 < 0 || score4 >10);
}
while (score4<0 || score4 >10);
do
{
cout << "Enter judges score: ";
cin >> score5;
do
{
if (score5 < 0 || score5 >10)
{
cout << "Score has to range from 0-10 \n";
cout << "Please enter a valid score: ";
cin >> score5;
}
}while (score5 < 0 || score5 >10);
}
while (score5<0 || score5 >10);
return;
}
//Start of calcScore
void calcScore( double score1, double score2, double score3, double score4,double score5)
{
double average;
average = (score1+score2+score3+score4+score5)/ 5;
return;
}
答案 0 :(得分:0)
让我们先处理你的错误:正如@ shree.pat18在评论中指出的那样,你正在调用一个函数并尝试给出参数的类型。这是不允许的。 C ++ 知道参数的类型,因为您之前已经声明了它们。您可以这样致电calcScore
:
double score1=-9.0;
double score2=-9.0;
double score3=-9.0;
double score4=-9.0;
double score5=-9.0;
getJudgesData();
calcScore(score1, score2, score3, score4, score5);
然而,这会带来一个新问题:在编译时,编译器不知道名为calcScore
的函数,该函数采用类型为double
的5个参数。
您正在声明两个名为calcScore
的函数:一个是简单声明的,没有定义没有参数,另一个是使用参数声明和定义的:
// just a declaration. This function has no definition and will not link
void calcScore();
和
// declared and defined
void calcScore( double score1, double score2, double score3, double score4,double score5)
{
}
您可以删除calcScore
的第一个声明,因为我假设您不需要两者,并将其更改为:
void calcScore(double score1, double score2, double score3, double score4, double score5);
现在,当您尝试在calcScore
中调用double
并传入5 main
时,编译器将知道您所指的功能。