Question
In the game Blackjack players get two cards to start with. Then they are asked if they want more cards. Players can continue to take
In the game "Blackjack" players get two cards to start with. Then they are asked if they want more cards. Players can continue to take as many cards as they like. The goal is to get close to 21 without going over. If the total is greater than 21 we say the player "busted".
Write a command line game that plays a simple version of blackjack. The program should generate random numbers between 1 and 10 each time the player gets a card. It should keep a running total of the players cards, and ask the player whether or not it should deal another card. Sample output for the game is written below. Your program should produce the same output.
> First cards: 3, 2
> Total: 5
> Do you want another card? (y/n): y
> Card: 6
> Total: 11
> Do you want another card? (y/n): y
> Card: 7
> Total: 19
> Do you want another card? (y/n): n
Here is another sample run
> First cards: 10, 2
> Total: 12
> Do you want another card? (y/n): y
> Card: 6
> Total: 18
> Do you want another card? (y/n): y
> Card: 7
> Total: 25
> Busted.
Suggestion
I highly highly suggest you grow your program in small steps. Start with a small amount of functionality, and then grow it gradually. This way you can compile and run your program after each statement that you write. We should discuss this on the discussion boards.
You might start by just generating a single card. The program execution might look like this:
> First card: 3
Then generate two cards
> First cards: 3, 2
Next add a variable to store the total, and a statement to show its value:
> First cards: 3, 2
> Total: 5
Next read in a user response and print out the value that was entered
> First cards: 3, 2
> Total: 5
> Do you want another card? (y/n): y
> You entered: y
Next you might add a loop, without yet adding the blackjack logic
> First cards: 3, 2
> Total: 5
> Do you want another card? (y/n): y
> Do you want another card? (y/n): y
> Do you want another card? (y/n): n
Now move the display of the total to the loop
> First cards: 3, 2
> Total: 5
> Do you want another card? (y/n): y
> Total: 5
> Do you want another card? (y/n): y
> Total: 5
> Do you want another card? (y/n): n
Your next steps might be something like this:
Generate a new card in each loop and display the value
Update the total in each loop.
Check to see if the user busts in each loop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started