Question
C++ Language get the program just like the Examples with what I have so far!! USE my Program please Code I have so far help
C++ Language get the program just like the Examples with what I have so far!! USE my Program please
Code I have so far help add on to it
#include
#include
#include
#include
#include
using namespace std;
int GetRandom (int min, int max);
string DealCard( int cards[], int player);
int ScoreHand (int cards[], int player);
int main(){
int cards[52];
int numplayer;
int i;
int score;
string firstcard;
string secondcard;
for (i=0; i<52; ++i){
cards[i]=0;
}
srand (time(NULL));
firstcard = DealCard (cards,i);
secondcard = DealCard (cards,i);
score =ScoreHand (cards,i);
cout <<"Dealer has cards: "< return 0; } int GetRandom (int min, int max){ return min+rand()%(max-min+1); } string DealCard (int cards[], int player){ string Ctype []={"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; char Csuit []= {'H','S','D','C'}; string cardvalue; int hold; hold=GetRandom (0,51); if (cards[hold]==0){ cardvalue = Ctype [hold%13]+Csuit[hold/13]; cards[hold]=player; } return cardvalue; } int ScoreHand (int cards[], int player){ int i; int sum=0; for (i=0; i<52; ++i){ if (cards[i]==player){ if ((i%13)>9){ sum+=10; } else{ sum += (i%13) +1; } } } return sum; } Assignment You will write a program that plays the card game, Blackjack, with a player. You will have exactly two players, the player him/herself and the dealer. Both will work off of the same deck of 52 cards, so no cards will be duplicated between the dealer and player. For purposes of this program, the Blackjack rules will be simplified. Each card has a value: Ace - 1 point 2, 3, 4, 5, 6, 7, 8, 9, 10 - Value of card (2, 3, ..., 10 points) Jack, Queen, King - 10 points Each card also has one of four suits: Ace of Hearts, Ace of Clubs, Ace of Spades, Ace of Diamonds King of Hearts, ..., and so on. For purposes of this program, the card value and suit will be abbreviated as: AH = "Ace of Hearts" AC = "Ace of Clubs" AD = "Ace of Diamonds" AS = "Ace of Spades" 2H, 3C, 4D,..., KH, and so on. The point of the game is to get to the value 21 without going over. You have two "responses", hit or stand. Hit means the dealer will provide you an extra card. Stand means you'll take the score of all of the cards you currently have. You should prompt the user for a response again if an invalid input is provided. If your score is above 21, it is called a "bust", and you lose. If your score is 21, you automatically win without the dealer having a chance to play. After you stand, the dealer plays the game and tries to get above your score. For purposes of your programmed dealer, it will keep "hitting" until it has a card value greater than or equal to the value 18. If the value is 18 or higher, the dealer will always stand. If the dealer goes above 21, then it will automatically lose, and the player will win. If the player and dealer have not gone above 21, then the scores are compared. Whomever has the higher score wins. If both have the same score, they tie in a "draw". The output is in "Examples" below. The only formatting requirement is that all of the cards must be in a left-justified field, 20 characters wide. Example Example: Example: Example:Dealer has cards: KD 3S (13) You have cards : QD AS (11) Hit or stand ? hit Dealer has cards: KD 3S (13) You have cards : QD AS 6D (17) Hit or stand ? stand Dealer hits : KD 3S KS (23) Dealer busts, player wins!
Dealer has cards: 4S 8D (12) You have cards : 9D 10H (19) Hit or stand ? hit Dealer has cards: 4S 8D (12) You have cards : 9D 10H 10C (29) Player busts, dealer wins!
Dealer has cards: KS 9D (19) You have cards : 9D 10H (19) Hit or stand ? stand Dealer has cards: KS 9D (19) You have cards : 9D 10H (19) Player and dealer draw.
Dealer has cards: 2S 9D (11) You have cards : 10D 10H (19) Hit or stand ? stand Dealer hits : 2S 9D 9S (20) Dealer stands : 2S 9D 9S (20) Dealer has cards: 2S 9D 9S (20) You have cards : 10D 10H (19) Dealer wins
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started