//BlackJack //Classic Gambling game where the player counts to 21. #include #include #include using namespace std; const int NUM_CARDS_IN_DECK = 13; //there are 13 cards in a suit; const int MAX_CARDS_IN_HAND = 11;//player's limit of how many card he can obtain in one hand. int main () { char again = 'y'; char approach = 'y'; //code from deck maker start srand((unsigned int)time(0)); //seeds random numbers for game int deck[NUM_CARDS_IN_DECK]; int value[NUM_CARDS_IN_DECK] = { 11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 }; char name[NUM_CARDS_IN_DECK] = { 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K' }; //deck end int randomNumber = rand(); //generate random number! int high = 21; int low = 10; int range = (high - low) + 1; int dealerNumber = rand()% range + low; int sum = 0; int i = 0; int handValueTotal = 0; int finalScore = 0; int startMoney = 120; //starting spending money finalScore += startMoney; int feePerRound = 20; //how much it costs to replay int tableFee = feePerRound; //amount player pays to get cards/play one round. int winnings = 0, moneyBet; //how much money the player will bet after seeing the cards. //deck maker start //initializing deck for( int i=0; i> approach; while (again == 'y') { cout << "how Much would you like to bet ?: "; cin >> moneyBet; finalScore -= tableFee; while (approach == 'y') { int choice; cout << "\nYour two cards: "; hand[numCardsInHand] = deck[currentDeckPosition]; cout << "\n " << name[hand[0]] << endl; if (numCardsInHand ==0) { numCardsInHand++; currentDeckPosition++; } hand[numCardsInHand] = deck[currentDeckPosition]; cout <<" " << name[hand[1]] << endl; if(numCardsInHand < 2) { for( int i=0; i 21) { cout << "\tBUST!"<< endl; cout << "You went over 21."<< endl; finalScore -= moneyBet; break; } cout << "\nYou have Currently: " <> choice; switch (choice) { case 1: cout<< "dealer got: "<< dealerNumber << endl; cout << "You got:" << handValueTotal<< endl; if(dealerNumber >handValueTotal) { cout << "you lose!"<< endl; finalScore -= moneyBet; cout << "You have Currently: " << finalScore << endl; break; } if(dealerNumber < handValueTotal) { cout << "You win!"<< endl; finalScore += moneyBet; cout << "You have Currently: " << finalScore << endl; break; } break; case 2: numCardsInHand++; currentDeckPosition++; hand[numCardsInHand] = deck[currentDeckPosition]; cout << "you were dealt: " << name[hand[numCardsInHand]]; break; case 3: cout << "how Much?: "<> moneyBet; break; case 4: cout << "Your total winnings are: " << finalScore <> again; numCardsInHand = 0; currentDeckPosition = 0; sum = 0; for( int i=0; i