Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a dealer to the game to the attatched code at the bottom in C++. There are two important blackjack rules to include: Dealers must

Add a dealer to the game to the attatched code at the bottom in C++. There are two important blackjack rules to include:

Dealers must take more cards as long as their total is less than 17

If the player and dealer tie it is called a push. The player does not win or lose money.

Here is sample output below. Notice that I have the user input a 'c' to continue between dealer cards. That keeps some of the suspense of the game.

> The dealer starts with a 10

> Your first cards: 10, 10

> Total: 20

> hit? (y/n): n

> Dealers has a 10...

> (c to continue) c

> Dealer gets a 10

> Total: 20

> Push!

> play again? (y/n): y

>

> The dealer starts with a 10

> Your first cards: 5, 10

> Total: 15

> hit? (y/n): y

> Card: 5

> Total: 20

> hit? (y/n): n

> Dealers has a 10...

> (c to continue) c

> Dealer gets a 6

> Total: 16

> (c to continue) c

> Dealer gets a 5

> Total: 21

> Dealer Wins!

> play again? (y/n): n

Current code that needs dealer added:

#include

#include

#include

using namespace std;

int main()

{

int total=0,card=0,nMaxCardValue =10,nBlackJack =21,dealer=10;

char cAnotherCard, cPlayAgain;

unsigned seed = time(0);

srand(seed);

//pg129 in book/ number range 1-10

do

{

card = (rand() % nMaxCardValue + 1);

cout << "First cards:" << card;

total+=card;

card = (rand() % nMaxCardValue + 1);

cout << "," << card << endl;

total+=card;

cout << "Total:"<< total << endl;

cout << "Do you want another card?(y/n):";

cin >> cAnotherCard;

while(cAnotherCard =='Y' || cAnotherCard == 'y')

{

card = (rand() % nMaxCardValue + 1);

cout << "Card:" << card << endl;

total+=card;

cout << "Total:"<< total << endl;

if (total > nBlackJack)

{

cout << "You Busted!!!" << endl;

total=0;

cAnotherCard = 'n';

}

else

{

cout << "Do you want another card?(y/n):";

cin >> cAnotherCard;

}

}

cout << "Would you like to play again? (y/n):";

cin >> cPlayAgain;

}while(cPlayAgain =='Y'|| cPlayAgain == 'y');

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel 2024 In 7 Days

Authors: Alan Dinkins

1st Edition

B0CJ3X98XK, 979-8861224000

More Books

Students also viewed these Databases questions

Question

1. How might volunteering help the employer and the employee?

Answered: 1 week ago