Question: Next, we will be writing a program that interprets pairs of playing cards as a blackjack hand and prints the overall value. Each card can

Next, we will be writing a program that interprets pairs of playing cards as a blackjack hand and prints the overall value. Each card can be only one of the following chars, 'A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2'.

  1. The values of an 'A' can be 1 or 11,
  2. the value of 'K', 'Q', and 'J' are each 10,
  3. the value of 'T' is 10,
  4. the value of all other cards is number of the card

To get you started, I have provided a partial program that outlines the idea of what you will need to do. Modify this program that takes two cards as chars and prints the overall value of the cards. If an 'A' is one of the cards, choose the appropriate value of 'A' (can be only 1 or 11), so that the total of the hand does not exceed 21. The final few lines of the program print the blackjack style determination of the score of the hand, this is there to guide you through debugging and testing. Be sure to be very thorough!

#includestdafx.h

#include using namespace std; /* This program uses two chars to store the value of two playing cards. The playing cards can only be the chars 'A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2', or '1'. This program will sum the cards to find the total as a hand in blackjack. The following is the key for the card values: * 'A' - Ace, is worth 1 or 11 * 'K', 'Q', 'J' - King, Queen , Jack are each worth 10 *'T', - Ten, worth 10 * All other are worth the numeric face of the card NOTE the value of Ace that ensures the total DOES NOT EXCEED 21 is to be used in calculation of the total. */ int main() { char cardOne = 'K'; char cardTwo = '7'; int total = 0; if (cardOne == 'A') { // do something } else if (cardOne == 'K' || cardOne == Q) { // do something else } // else if ( etc... else { cout << "ERROR!, cardOne: " << cardOne << " undefined" << endl; return 1; } /* etc... */ if (total == 21) { cout << "21!" } else if (total > 21) { cout << "Bust!"; } else { cout << total; } cout << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!