C++ 我不知道';我不理解这些编译错误

C++ 我不知道';我不理解这些编译错误,c++,C++,我不能编译,这个程序给了我错误。我已经花了三天时间了 C:\unisa\COS1511\test.cpp [警告]在“浮动CalcalAllowedPerchild(浮动)”功能中: 错误C:\unisa\COS1511\test.cpp:26 类型为float()(float)和const float到二进制运算符maxPerChild | | calcalallowedpercild的变量。在开始编程之前,我建议您读一本好书。您是真希。ng非常基本的错误。谢谢,现在我已经像你说的那样修改了它

我不能编译,这个程序给了我错误。我已经花了三天时间了

C:\unisa\COS1511\test.cpp
[警告]在“浮动CalcalAllowedPerchild(浮动)”功能中:

错误C:\unisa\COS1511\test.cpp:26
类型为
float()(float)
const float
到二进制
运算符maxPerChild | | calcalallowedpercild
calcalAllowedPerchild
函数的末尾,是否可以有一个

if ( allowedPerChild > maxPerChild || calcAllowedPerChild < minPerChild)
                                     //^^^^^^^^^^^^^^^^^ Error: Probably you
                                     // meant allowedPerChild. Change it.
函数应该如下所示:

void foo() {
    ... code ...
}
或:

取决于你的编码风格

编辑-您还需要更正拼写(MaxPercald)并声明
CalcalowedPerchild

float calcAllowedPerChild = maxPerUnit / nrChildren;

以及更改
CalcalAllowedPerchild
函数或
CalcalowedPerchild
变量的名称。不能让它们具有相同的名称。

此函数末尾不应有

float calcAllowedPerChild ( float nrChildren);

解决这个问题,看看会发生什么。

我建议检查分号-确保函数声明看起来不像原型

float calcAllowedPerChild ( float nrChildren);
                                          // ^ : Error - reomove it.
函数原型以
结尾,但不是函数定义。还可以查看
if
语句条件-

if ( calcAllowedPerChild > maxPerChild || calcAllowedPerChild < minPerChild)
这一行:

float calcAllowedPerChild ( float nrChildren);
结尾不应有分号。应为:

float calcAllowedPerChild ( float nrChildren)
float calcAllowedPerChild (float nrChildren)
{    
    float allowedPerChild = maxPerUnit / nrChildren;

    if (allowedPerChild > maxPerChild || allowedPerChild < minPerChild)
        return maxPerChild;
    else
        return minPerChild;
}
const float maxPerChild = 180.00;

嗯,是的,在函数定义中有一个额外的“;”:

float calcAllowedPerChild ( float nrChildren);

只要去掉这行末尾的分号就行了。当编译器说那行有一个额外的分号时,它正试图告诉你这一点。

删除
末尾的分号;
float calcAllowedPerChild(float nrchilds);

函数定义不以分号结尾。

这是您代码中的输入错误吗

const float maxPerChald = 180.00;
删除此行后的分号:

float calcAllowedPerChild ( float nrChildren);

CalcalowedPerchild有许多问题-应该是:

float calcAllowedPerChild ( float nrChildren)
float calcAllowedPerChild (float nrChildren)
{    
    float allowedPerChild = maxPerUnit / nrChildren;

    if (allowedPerChild > maxPerChild || allowedPerChild < minPerChild)
        return maxPerChild;
    else
        return minPerChild;
}
const float maxPerChild = 180.00;
应该是:

float calcAllowedPerChild ( float nrChildren)
float calcAllowedPerChild (float nrChildren)
{    
    float allowedPerChild = maxPerUnit / nrChildren;

    if (allowedPerChild > maxPerChild || allowedPerChild < minPerChild)
        return maxPerChild;
    else
        return minPerChild;
}
const float maxPerChild = 180.00;

这一行有一个分号
float calcalallowedperchild(float nrchilds);
,您可能不需要它。我删除了calcalowedperchild函数末尾的;但仍然给出了两个错误请帮助,现在给出了三个错误:“如果”之前的错误C:\COS1511\test.cpp:26错误C:\COS1511\test.cpp:29在“else”之前应为主表达式错误C:\unisa\cos151\test.cpp:29在“else”@queos之前应为“;”检查给出的提示。thaks我想我现在得到的是剩下的一个错误:错误C:\unisa\COS1511\test.cpp:26类型
float()(float)的无效操作数'和
const float'转换为二进制`operator@queos在C++中,如果使用变量,则应该在当前范围内声明并访问它。在本地范围或全局范围内没有被称为<代码> CalCaboWordPoPosie/COD>的变量。在开始编程之前,我建议您读一本好书。您是真希。ng非常基本的错误。谢谢,现在我已经像你说的那样修改了它,但仍然给出了三个错误:请帮助,现在给出了三个错误:错误C:\COS1511\test.cpp:26预期
,'或
;'before“if”错误C:\COS1511\test.cpp:29预期主表达式在“else”之前错误C:\unisa\COS1511\test.cpp:29预期`;before“else”@queos:你应该复制并粘贴上面的代码-你的代码中还有一个错误-将
if(allowedPerChild>maxPerChild | | calcalallowedPerchild
更改为
if(allowedPerChild>maxPerChild | allowedPerChild