'(' for function-style cast or construction type Xcode 错误
'(' for function-style cast or construction type Xcode error
This is where I get error:
calcScore(double score1,double score2, double score3, double score4, double score5);
这是我的代码,我不知道如何修复错误;我不确定错误是什么意思。我已经尝试查看教科书和在线示例,但我仍然感到困惑;这是我们必须使用 function
的第一个作业
#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;
}
让我们先处理你的错误:正如@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
的函数接受 5 个 double
类型的参数。
您正在声明两个名为 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
并在 main
中传入 5 double
时,编译器将知道您指的是什么函数。
This is where I get error:
calcScore(double score1,double score2, double score3, double score4, double score5);
这是我的代码,我不知道如何修复错误;我不确定错误是什么意思。我已经尝试查看教科书和在线示例,但我仍然感到困惑;这是我们必须使用 function
的第一个作业#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;
}
让我们先处理你的错误:正如@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
的函数接受 5 个 double
类型的参数。
您正在声明两个名为 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
并在 main
中传入 5 double
时,编译器将知道您指的是什么函数。