用于函数样式转换或构造类型的Xcode错误

用于函数样式转换或构造类型的Xcode错误

本文介绍了'('用于函数样式转换或构造类型的Xcode错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


calcScore(double score1,double score2,double score3,double score4,double score5);

这里是我的代码,我不知道如何解决错误;我不确定错误的含义。我试过在教科书和网上看例子,但我仍然感到困惑;这是我们必须使用函数的第一个任务

  #include< iostream> 
使用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(双倍1,双倍2,双倍3,双倍4,双倍5);

返回0;
}

// getJudgesData程序
void getJudgesData(double& score1,double& score2,double& score3,double& score4,double& score5)
{

do
{
cout<< 输入法官评分:;
cin>> score1;
do
{
if(score1 {
cout<< 得分范围从0-10 \\\
;
cout<< 请输入有效分数:;
cin>> score1;
}
} while(score1< 0 || score1> 10);
}
while(score1 10);

do
{
cout<< 输入法官评分:;
cin>> score2;
do
{
if(score2 {
cout< 得分范围从0-10 \\\
;
cout<< 请输入有效分数:;
cin>> score2;
}
} while(score2 }
while(score2
do
{
cout<< 输入法官评分:;
cin>> score3;
do
{
if(score3 {
cout<< 得分范围从0-10 \\\
;
cout<< 请输入有效分数:;
cin>> score3;
}
} while(score3 10);
}
while(score3 10);

do
{
cout<< 输入法官评分:;
cin>> score4;
do
{
if(score4 {
cout<< 得分范围从0-10 \\\
;
cout<< 请输入有效分数:;
cin>> score4;
}
} while(score4< 0 || score4> 10);
}
while(score4
do
{
cout<< 输入法官评分:;
cin>> score5;
do
{
if(score5 {
cout<< 得分范围从0-10 \\\
;
cout<< 请输入有效分数:;
cin>> score5;
}
} while(score5 10);
}
,(分数5 10);

return;
}

// calcScore开始
void calcScore(双分1,双分2,双分3,双分4,双分5)
{
double平均;

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(得分1,得分2,得分3,得分4,得分5);

然而,这会带来一个新问题:在编译时,编译器不会了解一个名为 calcScore 的函数,该函数需要5个 double 类型的参数。



您声明了两个名为 calcScore 的函数:一个是简单声明的,没有定义参数,另一个声明和定义参数:

  //只是一个声明。此函数没有定义,并且不会链接
void calcScore();

  //声明和定义
void calcScore(双分1,双分2,双分3,双分4,双分5)
{
}

您可以删除第一个 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);

here is the my code, I do not know how to fix the error; I am not sure what the error means. I've tried looking at examples in textbook, and online but I am still confused; this is first assignment where we have to use 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;
}
解决方案

Let's deal with your error first: as @shree.pat18 points out in the comments, you are calling a function and trying to give the type of the parameters. This isn't allowed. C++ knows the type of the parameters because you declared them previously. You can call calcScore like so:

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);

However, that brings you to a new problem: At the time of compilation, the compiler doesn't know about a function called calcScore which takes 5 parameters of type double.

You are declaring two functions called calcScore: one is simply declared and not defined with no parameters, and the other is declared and defined with parameters:

// just a declaration. This function has no definition and will not link
void calcScore();

and

// declared and defined
void calcScore( double score1, double score2, double score3, double score4,double score5)
{
}

You can remove the first declaration of calcScore since I assume you don't need both, and change it to be:

void calcScore(double score1, double score2, double score3, double score4, double score5);

Now when you try to invoke calcScore and pass in 5 double within your main, the compiler will know what function you are referring to.

这篇关于'('用于函数样式转换或构造类型的Xcode错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 08:42