After testing this program and seing it worked, I tried to simplify the if condition:
1 2 3 4
if (number1==number2==number3==1)
{
cout<<"You won 1$ \n";
}
I tested it and saw that it's not precise, and even non winning combinations (like 2 2 1 or 3 3 1) would make me win 1$. Can someone explain me why it doesn't work?
Thanks!
PS: I know that my "try again" isn't perfect because if someone enters another letter than 'y' or 'n' it would still repeat. I just didn't want to lose my time on this.
A easy way to shorten it would be just to test the variables against eachother. If number1 is equal to number2 and number2 is equal to number3 that means there was a winner. Then you can just print whatever number is in them variables to tell the user how much they have won.
It doesn't work because of the order of evaluations.
(number1==number2==number3==1)
gets evaluated in several steps:
First, number1==number2 are compared. This results in a true or false boolean result. This result is then compared to number3, again resulting in a bool result. This bool result is then compared to the number 1.