需要 C++ 语法错误帮助,'}'之前缺少';'

c++ syntax error help needed, missing ';' before '}'

本文关键字:C++ 帮助 需要 语法 错误      更新时间:2023-10-16
else if((RI >= 181) && (RI <= 210)){
        if((ICT1 = false) || ((ICT2 = false) || (ICT3 = false))){
        cout << "ICT n";
        if(ICT1 = false){
            ICT1 = true;
            goto endICT;
        }
        if(ICT2 = false){
            ICT2 = true;
            goto endICT;
        }
        if(ICT3 = false){
            ICT3 = true;
            goto endICT;
        }
            endICT:
    }

你好!这只是我程序的一部分,这段代码出现了几次,有不同的变量和其他东西。当我编译代码时,我得到"错误C2143:语法错误:在'}'之前缺少';'"我是新的所有这些编码,并将感谢任何帮助!谢谢你的时间!编辑:对不起,我之前没有包含足够的代码!基本上是随机选择一个数字,如果它在一个范围内,它就会经过这一部分。这个范围只能被选择3次,因为第一个"if"将不为真。谢谢你到目前为止的帮助!错误也在'endICT:'行。

插入一个空语句:

                   if(ICT3 = false){
        ICT3 = true;
        goto endICT;
    }
        endICT: ;
}

首先注意,使用goto语句被认为是一种不好的做法。只有在没有其他选择的情况下才能使用。

这段代码还有一些其他的东西。我在代码

中注释了一些
if(ICT3 = false) //this will assign value false into variable ICT3
     //you might want to write if(ICT3 == false) to compare and execute
{
   ICT3 = true;
   goto endICT; //this goto statement is completely redundant
}
//I assume that you want to have some code here, that does not execute
//if ICT3 == false in the first place... You should use if() ... else
//statement instead
endICT: ; //You are missing some ; here should be enough
}

有关C/c++中流控制语句的更多信息,请访问此处。有关C/c++中操作符的更多信息,请参考

编译器可能与您的标签混淆了endICT:

这在语义上等同于您发布的代码:

else if ( RI >= 181 && RI <= 210 )
{
    cout << "ICT n";
    if ( ! ICT1 )
        ICT1 = true;
    else if ( ! ICT2 )
        ICT2 = true;
    else if ( ! ICT3 )
        ICT3 = true;
}