Coding help (Black Jack)

Discussion in 'C' started by jpaulinedee, Aug 26, 2012.

1. jpaulinedeeNew Member

Joined:
Aug 26, 2012
Messages:
1
0
Trophy Points:
0
So I'm doing a program for my class, and we're supposed to code a Black Jack game. Our professor already gave us the shuffle function. I attached the shuffle code and my code. It would really help you took time to look at it. (( it's only 2.4kb.

So you can see my problem is the if else part. Does any of you know how to shorten that? Also, there's a spec that says, the value of 1 changes. Example, if your hand is 7 and 1, the value of 1 will be 11, and the sum will be 18. But if you have 8, J and 1, the value of 1 will be 1, and the sum will be 19. I hope you get it. Another problem of mine is that, if I have two of the same cards, it only counts 1. Like, if I have 9 2 2, it only counts one 2, and the sum is only 11. Please anyone help me. ((((

2. hobbyistNew Member

Joined:
Jan 7, 2012
Messages:
141
0
Trophy Points:
0
That's a lot of rules.

What you could do is define a deck of cards; for example

Code:
```#define TWO      1
#define THREE    2
#define FOUR     4
#define FIVE     8
...

int hand = TWO | THREE | FIVE;
```
to find out if a given card exists in the hand, you could do

Code:
```if((hand & FIVE) == FIVE)
// five is in the hand
```
I don't know the rules of card games, but you could possibly use an array of ints for the hand; that way, you could check to see how many of each card there are.

Code:
```int cards[] = { TWO, FIVE, SEVEN, etc },
hand = cards[0] | cards[1] | card[N];
```
It *should* be okay to figure out how to score the hand from there.