You have a fundamental misunderstanding of how the || operator works.
|| looks at what is on the left and the right of it. If either side is nonzero (true), it gives you back nonzero (true). If both sides are zero (false), it gives you zero (false).
What is happening is this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
// assuming your variables are assigned to these values (which they aren't because you
// haven't assigned them yet... but whatever):
// r == 0
// g == 1
// b == 2
letter1 = (r)||(g)||(b);
// after subbing in variable contents...
letter1 = 0 || 1 || 2;
// the first || is evaluated first.
// "0 || 1". Since the right side is nonzero, the || will evaluate to nonzero (1)
// so "0 || 1" evaluates to "1". Leaving us with:
letter1 = 1 || 2;
// now the next || is evaluated
// "1 || 2". Since both sides are nonzero, the result is nonzero (1)
// so "1 || 2" evaluates to "1". Leaving us with:
letter1 = 1;
// so all you're doing with this line is assigning a value of 1 to your letter1 variable
|
Note this is bad for a few reasons:
1) It's pointless because r, g, and b have no real meaning here. You can have the same effect by just assigning 1 directly.
2) Assigning any value to letter1 defeats the purpose of getting letter1 from the user. By reassigning like this you are erasing what the user input and replacing it with a value of 1. If you just throw away what the user gives you, you might as well not be asking them for anything.
The question now is... why do you think you need to do this? You are already checking the contents of letter1,2,and 3 below on line 27:
if (x==letter1&&y==letter2&&z==letter3)
What's more... that line is actually
correct.
So if you're already properly getting user input for these letters on line 20. And properly checking to make sure they input the correct values on line 27 ... what do you need lines 21-26 for?