Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question
This assignment is a review of loops. Do not use anything more advanced than a loop, such as programmer-defined functions or arrays or classes.
If you know blackjack, you may be tempted to change the specifications below to make the game more "blackjack-like". Please don't. Be sure to follow these specs exactly and don't try to improve on them. You will be penalized if the specs are not met exactly.
In the card game named 'blackjack' players get two cards to start with, and then they are asked whether or not they want more cards. Players can continue to take as many cards as they like. Their goal is to get as close as possible to a total of 21 without going over. Face cards have a value of 10.
Write a command line game that plays a simple version of blackjack. The program should generate a random number between 1 and 10 each time the player gets a card. Each of the values (1 through 10) must be equally likely. (In other words, this won't be like real black jack where getting a 10 is more likely than getting some other value, because in
real black jack all face cards count as 10.) It should keep a running total of the player's cards, and ask the player whether or not it should deal another card. If the player hits 21 exactly, the program should print "Congratulations!" and then ask if the player wants to play again. If the player exceeds 21, the program should print "Bust." and then ask if
the player wants to play again. Sample output for the game is provided below. Your program should produce the same output.
If you'd like a little refresher on random number generation, see lesson 7.3.
Important Submission Note:
In order to make your code pass the zyBooks tests, you will need to comment out the line where you seed the random number generator (using srand()).
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: 18
Do you want another card (y/n)? n
Would you like to play again (y/n)? y
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
Bust.
Would you like to play again (y/n)? n
Suggestion
Be sure to use iterative development. 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.
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
expand button
Transcribed Image Text:This assignment is a review of loops. Do not use anything more advanced than a loop, such as programmer-defined functions or arrays or classes. If you know blackjack, you may be tempted to change the specifications below to make the game more "blackjack-like". Please don't. Be sure to follow these specs exactly and don't try to improve on them. You will be penalized if the specs are not met exactly. In the card game named 'blackjack' players get two cards to start with, and then they are asked whether or not they want more cards. Players can continue to take as many cards as they like. Their goal is to get as close as possible to a total of 21 without going over. Face cards have a value of 10. Write a command line game that plays a simple version of blackjack. The program should generate a random number between 1 and 10 each time the player gets a card. Each of the values (1 through 10) must be equally likely. (In other words, this won't be like real black jack where getting a 10 is more likely than getting some other value, because in real black jack all face cards count as 10.) It should keep a running total of the player's cards, and ask the player whether or not it should deal another card. If the player hits 21 exactly, the program should print "Congratulations!" and then ask if the player wants to play again. If the player exceeds 21, the program should print "Bust." and then ask if the player wants to play again. Sample output for the game is provided below. Your program should produce the same output. If you'd like a little refresher on random number generation, see lesson 7.3. Important Submission Note: In order to make your code pass the zyBooks tests, you will need to comment out the line where you seed the random number generator (using srand()). 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: 18 Do you want another card (y/n)? n Would you like to play again (y/n)? y 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 Bust. Would you like to play again (y/n)? n Suggestion Be sure to use iterative development. 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. 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
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education