This program analyzes a hand of a simplified version of poker. It’s simplified because there are only 4 cards in a hand, there are no face cards, there are no suits, and we don’t care about straights.
We input 4 cards with prompt, each of which must be an unsigned in the range [1,10]. (If input failure or card out of range, complain and die). Output the kind of hand, which will be one of
4 of a kind (for instance, 7 7 7 7)
3 of a kind (for instance, 10 10 1 10)
2 pair (for instance, 8 2 8 2)
1 pair (for instance, 8 1 10 1)
nothing (for instance, 3 1 7 4)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
if ( (w <= 1 && w >= 10) || (x <= 1 && x >= 10) || (y <= 1 && y >= 10 ) || (z <= 1 && z >= 10) )
{
switch ( (w==x) + (w==y) + (w==z) + (x==y) + (x==z) + (y==z) )
case 0 : cout <<"Nothing" << endl;
break;
case 1 : cout <<"1 Pair" <<endl;
break;
case 2 : cout <<"2 Pair" <<endl;
break;
case 3 : cout <<"3 of kind" <<endl;
break;
case 4 : cout <<"4 of kind" <<endl;
break;
}
else
die("Card out of range");
|