Question

In: Computer Science

Write a C++ program that scores a blackjack hand. In blackjack, a player receives from two...

Write a C++ 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. Write a C++ 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. Write a C++ 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. Write a C++ 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.

Solutions

Expert Solution

#include<iostream>
using namespace std;
int main()
{
   int noOfCard;
   int score;
   int count;
   char choice='Y';
   char input;
   while(choice =='y' || choice =='Y') // if user enter yes
   {
   score = 0; // to retract sum everytime user wants to play again
   count =0; // retract count
cout<<"Input must be between 2 and 5: ";
   cin>>noOfCard; // input
   if(noOfCard<2 || noOfCard >5)
cout<<"Wrong Input"<<endl; // wrong input
   else
   {
       for(int i = noOfCard; i>0; i--) // get input cards till count of cards no enter
       {
       cout<<"Input card number: ";
       cin>>input;
       if(input>='2' && input<='9') // calculate score according to it
       {
          score = score + 2 + (int)(input- '2');
       }
       else if (input =='j' || input =='J'||
input =='t'|| input =='T'
               || input =='q'|| input =='Q'||
input =='k'|| input =='K')
       {
       score=score+10;
       }
       else if (input =='a'|| input == 'A')
       {
       count++;
       }
      }
   }
if(count)
   {
       while(count>1)
       {
       score= score+1;
       count--;
       }
       if(score >10 && count == 1)
      {
      score= score+1;
       }
       else if(score <10 && count ==1)
       {
       score= score+11;
       }
   }
   if(score>21) // if score is greater than 21 means busted
{
       cout<<"Busted"<<endl;
}
   else // print score then
       {
       cout<<endl<<"Score: "<< score<<endl;
       }
       cout<<"Press 'Y' OR ' y': "<<endl;
       cin.ignore();
       cin>>choice;
   }
   cout<<"Thank You for playing"<<endl;
}

OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW

PLEASE GIVE A THUMBS UP


Related Solutions

Using C++, create a program that will input the 3 game scores of a player and...
Using C++, create a program that will input the 3 game scores of a player and then output the level of the player with a message.   Specifications Prompt the user to input 3 game scores (double values). Compute the weighted average (DO NOT JUST ADD AND DIVIDE BY 3!) score as follows: 20% for first game, 30% for second game, 50% for last game Earlier games are worth less in the weighted average; later games are worth more. Print...
Tony Gaddis C++ Tic-Tac-Toe Write a program that allows two players (player X and player O)...
Tony Gaddis C++ Tic-Tac-Toe Write a program that allows two players (player X and player O) to play a game of tic-tac-toe. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The players take turns making moves and the program keeps track of whose turn it is. Player X moves first. The program should run a loop that: Displays the contents...
Play a blackjack. Write a Java program that starts from a deck of 52 cards and...
Play a blackjack. Write a Java program that starts from a deck of 52 cards and one player plays again a dealer. Use a simple rule explained here. Ace can be counted as 1 only for simplicity. Jack, Queen, King are counted as 10. At the beginning, player receives two cards. Dealer receives two cards, but shows one and hides one. Program asks player if player wants to receive another card or not. (player can continue to receive new cards...
In C++ Write a program to store exam scores into a file. The program will ask...
In C++ Write a program to store exam scores into a file. The program will ask the user how many exam scores to enter. Then it will ask the user for each exam score and store them in a file called scores.dat The file output should have the following format: Exam 1: 97 Exam 2: 85
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
Write a C++ program to input 10 scores (range from 0-100), calculate the average, then display...
Write a C++ program to input 10 scores (range from 0-100), calculate the average, then display the student's name, and a letter grade such as A, B, C, D, or F. It shall have a Student class with necessary private data members and constructor and public methods, such as getName, getGrade, calcScore, convertToGrade, etc. Try to create a Student object in main(), then invoke its methods to perform the tasks.
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
Java: Simple 21 Game (Blackjack) In this game, the dealer deals two "cards" to each player,...
Java: Simple 21 Game (Blackjack) In this game, the dealer deals two "cards" to each player, one hidden, so that only the player who gets it knows what it is, and one face up, so that everyone can see it. There are four players: one human player (user) and three computer players. The players take turns requesting cards, trying to get as close to 21 as possible, but not going over 21. A player may pass. Once a player has...
C++ PLEASE Write a new program called Lab15A Write a void function named fillArray that receives...
C++ PLEASE Write a new program called Lab15A Write a void function named fillArray that receives an array of 10 integers as a parameter and fills the array by reading the values from a text file (Lab15A.txt). It should also print the values of the array all on the same line, separated by spaces. Write an int function named findLast that receives an array of 10 integers as a parameter and returns the last negative number in the array. Write...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT