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!
#include<iostream>
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', or '2'. 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; //
together K and 7 should yield a total of 17
if (cardOne == 'A')
{
total += 11;
} else if (cardOne ==
'K' || cardOne == ‘Q’) {
total += 10;
} // 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;
}
Here is the solution to above problem in C++. Please read the code comments for more information
C++ CODE
#include<iostream>
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', or '2'. 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';
cout<<"ENTER FIRST CARD :";
cin>>cardOne;
cout<<"ENTER SECOND CARD: ";
cin>>cardTwo;
int totalA1_1 = 0; //this variable is used to store when card one
is A and we take it's value as 1
int totalA1_11=0; //this variable is used to store when card one is
A and we take it's value as 11
int totalA2_1=0; //this variable is used to store when card TWO is
A and we take it's value as 1
int totalA2_11=0;//this variable is used to store when card TWO is
A and we take it's value as 11
if (cardOne == 'A') {
{
totalA1_11 += 11;
totalA1_1+=1;
}
} else if (cardOne == 'K' || cardOne == 'Q'||cardOne ==
'J'||cardOne == 'T') {
totalA1_1 += 10;
totalA1_11+=10;
} else if(((int)(cardOne-'0') >=2 )&&((int)(cardOne-'0')
<10 ))
{
totalA1_11+=(int)(cardOne-'0');
totalA1_1+=(int)(cardOne-'0');
}
else {
cout << "ERROR!, cardOne: " << cardOne << "
undefined" << endl;
return 1;
}
if (cardTwo == 'A') {
{
totalA2_11 += 11;
totalA2_1+=1;
}
} else if (cardTwo == 'K' || cardTwo == 'Q'||cardTwo ==
'J'||cardTwo == 'T') {
totalA2_1 += 10;
totalA2_11+=10;
} else if(((int)(cardTwo-'0') >=2 )&&((int)(cardTwo-'0')
<10 ))
{
totalA2_11+=(int)(cardTwo-'0');
totalA2_1+=(int)(cardTwo-'0');
}
else {
cout << "ERROR!, cardOne: " << cardTwo << "
undefined" << endl;
return 1;
}
//finding a combination which leads either to 21 or the maximum
value less than 21
int max=-999;
if((totalA1_1+totalA2_1)>max
&&(totalA1_1+totalA2_1)<=21)
{
max=(totalA1_1+totalA2_1);
}
if((totalA1_11+totalA2_1)>max
&&(totalA1_11+totalA2_1)<=21)
{
max=(totalA1_11+totalA2_1);
}
if((totalA1_1+totalA2_11)>max
&&(totalA1_1+totalA2_11)<=21)
{
max=(totalA1_1+totalA2_11);
}
if((totalA1_11+totalA2_11)>max
&&(totalA1_11+totalA2_11)<=21)
{
max=(totalA1_11+totalA2_11);
}
int total = max;
if (total == 21) {
cout << "21!";
} else if (total > 21) {
cout << "Bust!";
} else {
cout << total;
}
cout << endl;
return 0;
}
SCREENSHOT OF THE OUTPUT

Next, we will be writing a program that interprets pairs of playing cards as a blackjack...
Write a Java program to simulate Blackjack. The program should be as basic as possible while following the rules below. Thanks a. There is one deck of cards b. Cards are drawn randomly using (Shuffle() method) c. The value of a hand is computed by adding the values of the cards in hand d. The value of a numeric card such as four is its numerical value e. The value of a face card is 10 f. Ace is either...
Must be in C++ Question: Blackjack (twenty-one) is a casino game played with cards. The goal of the game to draw cards that total as close to 21 points as possible without going over. All face cards count as 10 points, aces count as 1 or 11, and all other cards count their numeric value. The game is played against a dealer. The player tries to get closer to 21 (without going over) than the dealer. If the dealer busts...
"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! #include <iostream> #include <cmath> #include <cstdlib> 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 <<...
For this assignment you will create a one-player variation of the game BlackJack. The game will be divided into five rounds. The goal of each round is to accumulate a hand of cards that gets as close to 21 without going over. At the beginng of the game you will start with a score of 100 points. After each round, the difference between your hand and 21 will be subtracted from your total score. The object of the entire game...
Need a blackjack code for my assignment its due in 3 hours: it has to include classes and object C++. Create a fully functioning Blackjack game in three separate phases. A text based version with no graphics, a text based object oriented version and lastly an object oriented 2D graphical version. Credits (money) is kept track of throughout the game by placing a number next to the player name. Everything shown to the user will be in plain text. No...
2. Counting cards in blackjack (as seen in movies such as Rainman, The Hangover and 21) consists in keeping track of a count: the higher the count, the more likely it is for the next card drawn to be a high card. One version of this uses the following setup: . the cards 2, 3, 4, 5, 6 are given the value +1, e the cards 7, 8, 9 are given the value 0, e the cards 10, J, Q,...
How do I start this c++ code homework? Write a code in C++ for a BlackJack card game using the following simplified rules: Each card has a numerical value. Numbered cards are counted at their face value (two counts as 2 points, three, 3 points, and so on) An Ace count as either 1 point or 11 points (whichever suits the player best) Jack, queen and king count 10 points each The player will compete against the computer which represents...
HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...
Create a simplified Blackjack game using the Deck and Card classes (download the attached files to start). There is also a "TestCard" class that creates a Deck and runs some simple code. You may choose to use this file to help you get started with your game program. 1) Deal 2 cards to the "player" and 2 cards to the "dealer". Print both the player's cards, print one of the dealer's cards. Print the total value of the player's hand. 2) Ask...
Recall that in a standard set of playing cards, there are 4 suits, {*, ,, and 13 ranks LA 2, 3, 4,5, 6, 7, 8.9, 10. J Q. K . There is a card for every (rank.suit) combination. A hand of cards is another word for set. A 5-card hand of cards is a set of cards with 5 elements. Poker is a game that is often played with 5-card hands. (For cach problem, your answer should be left in...