Hello, I just started learning C++ following the online tutorials on this site. It's all gone very smooth until I tried using boolean operators. Following the tutorial I'm now at Cprogramming.com Tutorial: If Statements and I've written the following code:
The way I understood it I should be able to use "if ( a == ( 2 || 3 ) ) " to make it write out the if command if "a" gets the value 2 or 3, but as of now, if I enter 1 it writes the if command. If i enter any other value it writes the else command.Code:#include <iostream> using namespace std; int main() { int a; cout << "Write either 1, 2, or 3: "; cin >> a; if ( a == (2 || 3) ) { cout << "You entered 2 or 3."; } else { cout << "You entered 1."; } cin.get(); cin.ignore(); return 0; }
Edit: Didn't quite preview enough.