I need a lot of help on this one. This is my last assignment and I am having some trouble with it. I need to write a blackjack game that has this
•All cards are dealt face up.
•You do not need to support splitting or double downs.
•You do not need to pay extra if the player hits 21 on the first two cards.
•You need to verify the user has enough in their bankroll to place a bet. Constantly ask the user for a valid bet.
•If the player's bankroll hits zero, print a message and exit.
•A deck must be represented as an array of cards. (See next.)
•A card must be represented as a structure where at least one member is an enumerated data type.
•Before each round the cards must be shuffled.
•Aces will be counted as only 11.
•At the end of each round ask the user if they want to play again.
•Your function to initialize the deck must order the cards from low to high, the two card through Ace in sets of four.
I am having trouble with how to make the user input the random seed and how to output just 2 random cards and how to add them together. Any help would be appreciated. Here is what I have so far.
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include <iostream>
#include <cstdlib>
using namespace std;
typedef enum
{
VALUE,
JACK,
QUEEN,
KING,
ACE
} FACE;
typedef struct
{
int value;
FACE f;
} CARD;
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;
CARD temp = deck[x];
deck[x] = deck[new_index];
deck[new_index] = temp;
}
}
int main()
{
srand();
CARD deck[52];
init_deck(deck);
shuffle_deck(deck);
print_deck(deck);
int bank;
int seed;
int bet;
cout << "Enter the initial bankroll" << endl;
cin >> bank;
cout << "Enter seed" << endl;
cin >> seed;
cout << "Seeding random number generator..." << endl;
cout << "== Blackjack v1.0 ==" << endl;
cout << "Initializing deck..." << endl;
init_deck(deck);
cout << "Shuffling deck..." << endl;
shuffle_deck(deck);
cout << "Enter bet:" << endl;
cin >> bet;
cout << "Current hand: " << srand(seed) % 3 << ".";
cout << "Player has: " << endl;
}
|