Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Blackjack 40 my teacher created this assignment and I need help. He is using c++ and has provided this template: Further instructions are below the

"Blackjack 40" my teacher created this assignment and I need help. He is using c++ and has provided this template: Further instructions are below the template! He has setup an autograding system, we have to match his inputs and outputs, he has provided input and output files but not the same exact ones he uses on the autograder, these are similar. He does this to prevent us from hardwiring our codes. I have provided the Input and Output files as well... Our code must also be capable of an ace... The code must not have excess outputs it must 100% match what he is asking, statements must be exactly identical to the autograders outputs.

------------------------------------------------------------------------------

Template Provided by Instructer:

#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 << "A WINNER IS YOU! GAME OVER! "; }

------------------------------------------------------------------------------------------------------------------

Assignment 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

-------------------------------------------------------------------------------------------------------

Input/Output Files:

InputFile 0: 1 3

OutputFile 0:

You currently have $100 and are betting $10 You drew a 11 You drew a 10 You drew a 10 You drew a 5 The total value of your cards is: 36 Do you wish to 1) Hit or 2) Stay or 3) Quit?

----------------- InputFile 1: 3 1 2 3

OutputFile 1:

Welcome to Blackjack-40!

You currently have $100 and are betting $10 You drew a 7 You drew a 9 You drew a 10 You drew a 4 The total value of your cards is: 30 Do you wish to 1) Hit or 2) Stay or 3) Quit? You drew a 7 The total value of your cards is: 37 Do you wish to 1) Hit or 2) Stay or 3) Quit? Dealer drew a 10 Dealer drew a 6 Dealer drew a 10 Dealer drew a 5 Dealer drew a 7 The total value of the dealer's cards is: 38 Dealer wins 10 dollars You currently have $90 and are betting $10 You drew a 6 You drew a 5 You drew a 4 You drew a 10 The total value of your cards is: 25 Do you wish to 1) Hit or 2) Stay or 3) Quit? ---------------- InputFile 2: 4 1 1 2 3

OutputFile 2:

Welcome to Blackjack-40!

You currently have $100 and are betting $10 You drew a 8 You drew a 10 You drew a 10 You drew a 2 The total value of your cards is: 30 Do you wish to 1) Hit or 2) Stay or 3) Quit? You drew a 9 The total value of your cards is: 39 Do you wish to 1) Hit or 2) Stay or 3) Quit? You drew a 10 The total value of your cards is: 49 BUSTED! Dealer drew a 4 Dealer drew a 2 Dealer drew a 10 Dealer drew a 10 Dealer drew a 2 Dealer drew a 9 The total value of the dealer's cards is: 37 Dealer wins 10 dollars You currently have $90 and are betting $10 You drew a 4 You drew a 10 You drew a 10 You drew a 8 The total value of your cards is: 32 Do you wish to 1) Hit or 2) Stay or 3) Quit? Dealer drew a 4 Dealer drew a 6 Dealer drew a 4 Dealer drew a 2 Dealer drew a 5 Dealer drew a 3 Dealer drew a 8 Dealer drew a 10 DEALER BUSTED! The total value of the dealer's cards is: 42 Player wins 10 dollars You currently have $100 and are betting $10 You drew a 5 You drew a 8 You drew a 8 You drew a 3 The total value of your cards is: 24 Do you wish to 1) Hit or 2) Stay or 3) Quit?

---------------------------

InputFile 4: 4 2 2 2 3

OutputFile 4:

Welcome to Blackjack-40!

You currently have $100 and are betting $10 You drew a 8 You drew a 10 You drew a 10 You drew a 2 The total value of your cards is: 30 Do you wish to 1) Hit or 2) Stay or 3) Quit? Dealer drew a 9 Dealer drew a 10 Dealer drew a 4 Dealer drew a 2 Dealer drew a 10 The total value of the dealer's cards is: 35 Dealer wins 10 dollars You currently have $90 and are betting $10 You drew a 10 You drew a 2 You drew a 9 You drew a 4 The total value of your cards is: 25 Do you wish to 1) Hit or 2) Stay or 3) Quit? Dealer drew a 10 Dealer drew a 10 Dealer drew a 8 Dealer drew a 4 Dealer drew a 6 The total value of the dealer's cards is: 38 Dealer wins 10 dollars You currently have $80 and are betting $10 You drew a 4 You drew a 2 You drew a 5 You drew a 3 The total value of your cards is: 14 Do you wish to 1) Hit or 2) Stay or 3) Quit? Dealer drew a 8 Dealer drew a 10 Dealer drew a 5 Dealer drew a 8 Dealer drew a 8 The total value of the dealer's cards is: 39 Dealer wins 10 dollars You currently have $70 and are betting $10 You drew a 3 You drew a 9 You drew a 5 You drew a 6 The total value of your cards is: 23 Do you wish to 1) Hit or 2) Stay or 3) Quit?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions