The following C++ code:
if (a != '0.5' || a != '0.6')
{
cout << "The answer is neither 0.5 nor 0.6 " << '\n';
}
I have also tried
if ((a != '0.5') || (a != '0.6'))
{
cout << "The answer is neither 0.5 nor 0.6 " << '\n';
}
and tried
if ( !(a== '0.5') || !(a==0.6)
{
cout << "The answer is neither 0.5 nor 0.6 " << '\n';
}
Receives a number from a user and checks if the number is 0.5 or 0.6; if it is it should execute as a false statement but if it's any other number it should execute as true. However, it keeps executing as true though it should execute as false when I enter 0.5 or 0.6. This is different when I use an else if statement in which it works fine that is:
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.
}
Why can't the != execute in the if statement?