Pocker

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");
	
Do you have a question?
Yes, I am not quite sure how does this line work
(w==x) + (w==y) + (w==z) + (x==y) + (x==z) + (y==z) )

and also the whole code is not working
It looks like the four cards are represented by variables w, z, y, z.

Each expression of the form (a==b) is a comparison that evaluates to 1 or 0. So I image that the intent is to identify the number of matching cards, as the sum of these individual expressions is the number of matches. But I haven't bothered to check that this is correct.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
	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 6: 
			cout <<"4 of kind" <<endl;
			break;
		}
	}
	else

		die("Card out of range");
	
}


I just fixed it !

also I guess last case should be 6 and instead of the || operator it should be &&
Last edited on
Topic archived. No new replies allowed.