Sam (assassin437) wrote in cpp,
Sam
assassin437
cpp

Hello!

I'm slowly working my way through learning C++, and have just come to logical operators. I tried an incredibly simple little thing just to make sure I understood the concepts, and apparently I don't.

The code ran:


1) cout << "Enter two numbers, of which only one should be a \'7\'"; 2) int a, b; 3) cin >> a; 4) cout << "\n"; 5) cin >> b; 6) 7) if (((a||b)&&!(a&&b)) == 7) 8) 9) {cout << "woo";} 10) 11) 12) return 0;


Which as far as I can tell should mean "if either a or b, but not both of them are a 7, print the line "woo""

The code compiles with no errors or warnings (using GCC Code::Blocks on Ubuntu Hardy), but refuses to print the line, whatever the input. Any help gratefully received.
  • Post a new comment

    Error

    default userpic
  • 20 comments