← Logical Operators & the Ternary Operator

Exactly One Switch On

hard

Two switches, each represented by an int where 0 means off and any nonzero value means on. Print On if exactly one of them is on – both off, or both on, both print Off.

This is worth building entirely out of &&, ||, and !, without writing a single if: “exactly one of two things is true” is “(the first is true and the second isn’t) or (the second is true and the first isn’t)” – translate that sentence directly into &&/||/!, one piece at a time, rather than trying to guess the whole expression at once. This also uses the ternary operator from this lesson to pick the string to print, all in one printf call.

Your solution

"Run" uses the sample stdin ("1 0"). "Submit" checks your code against all 5 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution