I have just finishing writing a program that simulates the casino game 'Three Card Poker'. I did it by creating an array of objects (my playing cards), shuffling them using a FOR statement, and then dealing them. I had a problem getting the program (compiler?) to recognise 3 of a kind hands however, and although I have solved this problem, I cannot seem to figure out why the first way did not work. I feel as though I am misunderstanding something and wondered if anyone could shed a light onto this.
There's nothing wrong with the code you've posted, by itself. There could be something wrong in the code that comes later that trashes the program state.
Player Hand Values = 2, 2, 2
Playerhand rank = 42.
The second compiles exactly the same, however the rank is incorrect for all different 3 of a kind values. i.e I compiled that code just and got the result:
1 2
Player Hand Values = 2, 2, 2
Playerhand rank = 7.
I assumed that it was an error in the code but helios suggests that the code is fine, as I originally thought myself. Confused :S
No it is not: http://ideone.com/u5DqxP
Minimal compiling example means code which we can compile and see your problem for ourselves.
Your code is indeed fine and that why I asked for code.
Sorry MiiniPaa, I misunderstood. As it turns out I accidentally fell upon the solution whilst doing something else, the problem was using == when equalling pcard1.value to pcard3.value. Using just = made it work, although i'm not sure why. Ill research operators some more to see if there is a reason for that. Thanks very much for the replies.
= doesn't compare the operands. It sets the variable on the left to the value on right and the whole expression evaluates to the value on the right. (x = y) == y regardless of the value of x.