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

时间:2013-04-01 22:27:36

标签: c++ syntax-error

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:'行中。

4 个答案:

答案 0 :(得分:4)

只需插入一个空语句:

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

答案 1 :(得分:4)

首先请注意,使用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 ++ go here中流控制语句的更多信息。 有关C / C ++ try this中运算符的更多信息。

答案 2 :(得分:0)

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

然后关闭)

答案 3 :(得分:0)

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

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