下面的C++代码:如果声明没有工作,我怎么想
if (a != '0.5' || a != '0.6')
{
cout << "The answer is neither 0.5 nor 0.6 " << '\n';
}
我也曾尝试
if ((a != '0.5') || (a != '0.6'))
{
cout << "The answer is neither 0.5 nor 0.6 " << '\n';
}
,并试图
if (!(a== '0.5') || !(a==0.6)
{
cout << "The answer is neither 0.5 nor 0.6 " << '\n';
}
从用户接收的数并检查数字是0.5还是0.6;如果是的话,它应该作为虚假陈述执行,但如果它是任何其他数字,它应该执行为真。但是,它始终保持为true,但当输入0.5或0.6时它应该作为false执行。这是不同的,当我使用一个else if语句在它正常工作是:
if (a != 0.5)
{
//what to do if true.
}
else if (a != 0.6)
{
//What to do if this is true and the first id wrong.
}
else
{
//What to do if none are true.
}
为什么不能在= if语句执行呢?
好吧,我不是故意的代码最终看起来像。 – urbanslug 2012-07-26 08:14:11
好吧,如何使用if(a!='x'|| a!='y'){}语句就是我想知道的。没有其他的请 – urbanslug 2012-07-26 08:15:40