Hi,
I have a couple of questions, if anyone wouldn't mind answering them.
1. If you compile the following program, a is recognised by the first if condition, but not the second. Can anyone explain why this is? It seems like in the second condition, (12 || 17 || 31 || 44) should just equate to either 1 or 0 like the first condition.
2. If you can't use something like the second if statement, is there a more efficient way to check whether a variable is one of several different values than via something like the first one?
Thanks.
Code:
#include <iostream>
using namespace std;
int main()
{
int a = 12;
if ((a == 12) || (a == 17) || (a == 31) || (a == 44))
cout << "a recognised by condition 1" << endl;
if (a == (12 || 17 || 31 || 44))
cout << "a recognised by condition 2" << endl;
}