Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that scores a blackjack hand. In blackjack, a player receives from two to five cards. The cards 2 through 10 are

 

Write a program that scores a blackjack hand. In blackjack, a player receives from two to five cards. The cards 2 through 10 are scored as 2 through 10 points each. The face cards (jack, queen, and king) are scored as 10 points. The goal is to come as close to a score of 21 as possible without going over 21. Hence, any score over 21 is called "busted". The ace can count as either 1 or 11, whichever is better for the user. The user is asked how many cards they have, and the user responds with an integer 2, 3, 4, or 5. The user is then asked for the card values. Card values are 2 through 10, jack, queen, king, and ace. A good way to handle input is to use the type char. Input the values 2 through 9 as the characters '2' through '9'. Input the values 10, jack, queen, king, and ace as the characters 't', 'q', 'k', and 'a'. Allow upper and lowercase letters. After reading in the values, the program should convert them from character values to numeric card scores, taking special care for aces. The output is either [2.21] or the word busted. Your program should include a loop that lets the user repeat this calculation until the user says they are done. You may have multiple long multiway branches.

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

A First Course In Mathematical Modeling

Authors: Frank R. Giordano, William P. Fox, Steven B. Horton

5th Edition

1285050908, 9781285050904

More Books

Students also viewed these Programming questions

Question

1. Make sure praise is tied directly to appropriate behavior.

Answered: 1 week ago