2013-04-01 51 views
2
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: 
    } 

你好! 这只是我的程序的一部分,这段代码出现了几次,有不同的变量和其他东西。当我编译代码时,出现“error C2143:Syntax Error:missing';'之前'}'“ 我是新来的所有这些编码,并会感谢任何帮助! 感谢您的时间! 编辑: 对不起,我之前没有包含足够的代码!基本上选择一个随机数,如果它在一个范围内,它会通过这个部分。这个范围只能选择3次,因为那么第一个'if'就不会是真的。 感谢您的所有帮助!此错误在'endICT:'行中。C++语法错误帮助需要,缺少';'之前}}

+5

那'goto'是毫无意义的。 – chris

+8

这整个事情可以用'ICT3 = true;'代替(假设你在if条件中表示'=='而不是'=')。 –

+0

你确定编译器在抱怨你复制的行吗?这可能是有意义的,添加一些上下文(前/后的行) –

回答

4

只需插入一个空语句:

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

做了这个改变,摆脱了错误,但现在我没有得到任何输出。我认为这是我需要的,现在需要找到新的问题。非常感谢您的时间! –

0

大概是编译器混淆您的标签 endICT:

随后是关闭)

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中的运算符的更多信息。

0

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

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