Write a modified version of Blackjack. This modified card game has cards numbered 1-
10. The player and dealer take turns, each receiving a card. The cards dealt should
alternate, between player and dealer, with the player receiving the first card, the dealer
receives the second card, etc. The program should then print out the player’s hand, as
well as only one of the dealer’s cards. The program prompts the user for another card.
The user can choose up to five cards total. After the user has finished “hitting” (the act of
getting another card), then the computer will deal its own hand, until either it arrives at
17, or busts by going over 21. Assume a “bottomless” deck.
If the user busts, display a message saying as much; don’t worry about printing out the
dealer’s hand. Otherwise, print out the dealer’s hand, and look at the possible options:
The dealer goes over 21 – the computer busts, and the player wins.
The player’s cards total more than the dealer’s cards – the player wins.
The dealer’s cards total more than the player’s cards – the dealer wins.
The player’s cards total the same as the dealer’s cards – it is a tie game.
Finally, prompt the user if he/she would like to play again.
using namespace std;
int dealCards(int, string);
void hit(int &);
void determineWinner(int, int);
int Random(int, int);
char keepPlaying = 'n'; //loop control variable
cout << "Would you like to play again (y/n)?";
cin >> keepPlaying;
} while(keepPlaying == 'y');
//play one hand of 21
//randomize the cards
// deal the cards
int person = dealCards(2, "Your Cards:");
cout << " = " << person << endl;
int house = dealCards(2, "Computers Cards:");
cout << " = " << house << endl;
// Ask if human wants a hit and keep hitting...
cout << endl;
//Determine if computer takes a hit
while ((house < person) && (house <= 21) && (person <= 21))
house += dealCards(1,"The Computer takes a card ");
cout << endl;
//show who won....
void determineWinner(int yourScore, int dealerScore)
//Compare the scores to see who won
if (yourScore == 21)
cout << "You have 21. You win!" << endl;
else if ((yourScore < 21) && (yourScore > dealerScore))
cout << "Dealer busts; You win!" << endl;
cout << "You lose" << endl;
int dealCards(int numberOfCards, string message)
//This function deals the cards
int return_value = 0;
int value = 0;
for (int b = 0; b <= numberOfCards; b++)
int cards = b;
value = Random(0,10);
cout << value << " ";
cout << " , ";
return_value += value;
void hit(int &playerScore)//This function asks you if you want another card -- 'a hit'
int cardCount = 0;
char wantCard = "y" || "n";
int cardTotal = 0;
cardTotal = playerScore;
cout << "Would you like another card?";
while (wantCard == 'y')
if ((cardTotal > 0 ) && (cardTotal < 21))
cout << "Do you want another card?";
cin >> wantCard;
if (wantCard == 'y')
cout << cardTotal + dealCards(1, "You take a card."); // adds yourScore to dealCard()
cout << "You decide to stay";
if (cardTotal > 21)
cout << "You have gone over 21, You Lose";
int Random(int upperbound, int lowerbound)
//returns a random number within the given boundary
result= 1 + rand() % (upperbound - lowerbound + 1);