### blackjack program.

 I was pulling out a random card from an already randomized deck. Like playing blackjack and pulling cards from the middle. Sorry guys!
Can this thread remain open? I will need more help and would love the input of the people on this site.

Hey I've only just started the basics of this program and I'm wondering if anyone can shed some light on an issue I'm having.

My instructor uses hypergrade so my program has to match his results to the T.

Problem:
My cards dont match his for user and dealer.

Example:
Using rand() with a seed of (1) his user cards are 4,10 and dealer 10,10.
Mine are 11,9 and 10, 10.

Heres the code:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249`` ``````#include #include #include #include #include #include #include #include using namespace std; typedef enum { VALUE, JACK, QUEEN, KING, ACE } FACE; typedef struct { int value; bool inplay; FACE f; } CARD; float cash; CARD userhand[2]; CARD dealerhand[2]; void dealerdeck(CARD deck[]) { int card2=0; for(int o=0; o<=1; o++) { do { card2 = rand() % 52; cout << " dealers cards are: " << deck[card2].value<< endl; }while(deck[card2].inplay = false ); deck[card2].inplay = false; dealerhand[o].value = deck[card2].value; } } void userdeck(CARD deck[]) { int card1=0; for(int x=0; x<=1; x++) { do { card1 = rand() % 52; cout << "players cards are: " << deck[card1].value<< endl; }while(deck[card1].inplay = false ); deck[card1].inplay = false; userhand[x].value=deck[card1].value; } } void seeder () { int seed; cout << "Seed the random number generator" << endl; cin >> seed; srand(seed); } void bankroll() { cout << "Enter your bankroll" << endl; cin >> cash; } bool checkbankroll() { if (cash <= 0) { cout << "Out of money" << endl; return true; } return false; } void print_card(CARD c) { if (c.f == ACE) cout << "ACE (11)"; else if (c.f == KING) cout << "KING (10)"; else if (c.f == QUEEN) cout << "QUEEN (10)"; else if (c.f == JACK) cout << "JACK (10)"; else if (c.f == VALUE) { if (c.value == 10) cout << "TEN (10)"; else if (c.value == 9) cout << "NINE (9)"; else if (c.value == 8) cout << "EIGHT (8)"; else if (c.value == 7) cout << "SEVEN (7)"; else if (c.value == 6) cout << "SIX (6)"; else if (c.value == 5) cout << "FIVE (5)"; else if (c.value == 4) cout << "FOUR (4)"; else if (c.value == 3) cout << "THREE (3)"; else if (c.value == 2) cout << "TWO (2)"; else cout << "Value not recognized"; } else cout << "Face not recognized"; } void init_deck(CARD deck[]) { for (int index = 0; index < 4; index++) { int seg = index * 13; deck[seg + 0].f = VALUE; deck[seg + 0].value = 2; deck[seg + 1].f = VALUE; deck[seg + 1].value = 3; deck[seg + 2].f = VALUE; deck[seg + 2].value = 4; deck[seg + 3].f = VALUE; deck[seg + 3].value = 5; deck[seg + 4].f = VALUE; deck[seg + 4].value = 6; deck[seg + 5].f = VALUE; deck[seg + 5].value = 7; deck[seg + 6].f = VALUE; deck[seg + 6].value = 8; deck[seg + 7].f = VALUE; deck[seg + 7].value = 9; deck[seg + 8].f = VALUE; deck[seg + 8].value = 10; deck[seg + 9].f = JACK; deck[seg + 9].value = 10; deck[seg + 10].f = QUEEN; deck[seg + 10].value = 10; deck[seg + 11].f = KING; deck[seg + 11].value = 10; deck[seg + 12].f = ACE; deck[seg + 12].value = 11; } } void print_deck(CARD deck[]) { for (int x = 0; x < 52; x++) { print_card(deck[x]); cout << endl; } } void shuffle_deck(CARD deck[]) { for (int x = 0; x < 52; x++) { int new_index = rand() % 52; // newindex = remainder of random divided by 52 CARD temp = deck[x]; // temp is a card in deck[x] deck[x] = deck[new_index]; // card in deck[x] = random number newindex deck[new_index] = temp; // random card in deck is now temp } } void setupdeck() { seeder(); CARD deck[52]; init_deck(deck); shuffle_deck(deck); print_deck(deck); userdeck(deck); dealerdeck(deck); } int main() { setupdeck(); //bankroll(); } ``````

Last edited on
In a card game, it's typical that you deal off the top of the deck not the middle of the deck, or the bottom of the deck. We normally call that cheating.

I haven't found the problem, but I suspect it is due to your dealer deck and user deck functions. It looks like your pulling cards from 26-29. I figure if I tell you that, you might can fix it quicker than I could.

 26 ACE (11) 27 NINE (9) 28 JACK (10) 29 KING (10)

 Seed the random number generator 1 1 FOUR (4) 2 TEN (10) 3 JACK (10) 4 JACK (10) 5 SIX (6) 6 NINE (9) 7 ACE (11) 8 SIX (6) 9 TWO (2) 10 SIX (6) 11 EIGHT (8) 12 TWO (2) 13 QUEEN (10) 14 SEVEN (7) 15 ACE (11) 16 KING (10) 17 KING (10) 18 JACK (10) 19 THREE (3) 20 FOUR (4) 21 TEN (10) 22 SEVEN (7) 23 FIVE (5) 24 QUEEN (10) 25 FIVE (5) 26 ACE (11) 27 NINE (9) 28 JACK (10) 29 KING (10) 30 FIVE (5) 31 TWO (2) 32 EIGHT (8) 33 THREE (3) 34 NINE (9) 35 FOUR (4) 36 THREE (3) 37 TEN (10) 38 THREE (3) 39 QUEEN (10) 40 FIVE (5) 41 ACE (11) 42 SEVEN (7) 43 SIX (6) 44 TEN (10) 45 EIGHT (8) 46 FOUR (4) 47 KING (10) 48 QUEEN (10) 49 SEVEN (7) 50 NINE (9) 51 TWO (2) 52 EIGHT (8) players cards are: 11 players cards are: 9 dealers cards are: 10 dealers cards are: 10
Last edited on
I also see in userdeck, if you comment out
`// card1 = rand() % 52; `

The first card shows up correct.
Topic archived. No new replies allowed.