Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a assignment in C++ that i could not figure out. These are the instructions : For this assignment, you will be playing a

I have a assignment in C++ that i could not figure out.

These are the instructions :

For this assignment, you will be playing a variant of Blackjack where the player tries to get as close to 40 as possible without going over. The player starts with $100 and always $10 per hand. If they go over, they "go bust" and pay $10 to the dealer.

Once they finish, the dealer will go, and will draw cards until they get a 36 or higher. If the dealer goes over 40, the dealer goes bust and pays $10 to the player if they have not gone bust.

If the dealer doesn't go bust, then the dealer's score is compared with the score of the player. If they player is higher than the dealer's, they gain $10, they lose $10 if they have less, and no money is exchanged on a tie.

The value of a card is the face value (i.e. an 8 is worth 8 points, a jack/queen/king is worth 10) except for aces, which count either as 11 or 1, whichever is more advantageous for the player. I recommend when you start just always treating it as an 11 and worrying about handling this after doing everything else.

Playing a game of Blackjack-40: 1) The player is initially dealt four cards 2) If they are dealt a 40, they print "BLACKJACK 40!" and they win $20. 3) They can choose to hit or stay or quit. Hit means they are dealt another card. If they hit and go over 40, they go bust and pay $10 to the dealer. If they hit they can continue hitting until they bust or choose to stay or quit. Stay means they keep their total and the dealer gets to go. Quit means the game terminates. 4) After the player is done, deal cards for the dealer until they get a 35 or higher. 5) Handle the money payments as described above. If the player wins they gain $10, if they lose they lose $10, if they tie no money is exchanged. 6) If the player hits $200 they win the game, if they hit $0 they lose the game, and the game ends. 7) Otherwise, go back up to #1 and do it again

Here is the template:

#include #include #include using namespace std;

//Will return a number from 1 to 13, representing the face of a card int draw_card() { return rand() % 13 + 1; }

int main() { const int BET = 10; //This will allow you to control chance, to make testing easier cout << "Please choose a random seed, or 0 to use the current time: "; int seed = 0; cin >> seed; if (seed == 0) srand(time(0)); else srand(seed);

cout << "Welcome to Blackjack-40! ";

//YOU: Create an integer named money and set it to 100

//YOU: Do this (and all lines below) in an infinite loop...

cout << "You currently have $" << money << " and are betting $" << BET << endl;

//YOU: For each player...

//YOU: Make an integer called total holding the total value of the players card and initialize it to 0 //YOU: Using a for loop, deal 4 cards to the player int card = draw_card(); //This is how you deal a card //YOU: Handle face cards. I.e., if the card is >= 10 set the card to 10

//YOU: Handle aces (a 1 is worth 11) cout << "You drew a " << card << endl;

//YOU: Add the card's value to the total

//Then we print the total cout << "The total value of your cards is: " << total << endl;

//YOU: Make an infinite loop for the players drawing cards until they bust or stay or quit cout << "Do you wish to 1) Hit or 2) Stay or 3) Quit? ";

//YOU: After the players are done, draw cards for the dealer until they get a 35 or higher, or bust cout << "Dealer drew a " << card << endl;

//YOU: Check for loss. If the player has 0 dollars or less, they lose cout << "YOU LOSE! GAME OVER! ";

//YOU: Check for win. If the player has 200 dollars or more, they win cout << "YOU WIN ";

}

}

It should only display "Blackjack 40!" if the player hits 40 in the first round and if the user presses another number or letter it should display BAD INPUT.

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

Step: 3

blur-text-image

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

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions

Question

4. What actions should Bouleau & Huntley take now?

Answered: 1 week ago