In: Computer Science
Hello, I very stuck on this c++ blackjack project and was wondering if anyone can offer help and guidance on this subject
can someone help he with part 4 i have no idea how to approach the problem and how to do it
I have compeleted a few parts to this project they are listed below
Part 1 – Displaying Cards Write a function to display (print) a card. sample program output void displayCard(int card) Prints the name of the card (ten of spades, queen of diamonds etc.). The parameter should be a value between 1 and 13, from which the type of card can be determined (1 = ace, 2 = two, …, 10, == ten, 11 = jack, 12 = queen, 13 = king). The card suit (clubs, diamonds, hearts or spades) should be determined randomly.
Part 2 – Generating Cards Write a function to get a card. int getCard() Returns a random value between 1 and 13, representing a card (ace, 2, …, queen, king). You do not have to keep track of which cards are dealt. So, if the game deals the queen of spades five times in row that is perfectly acceptable.
Part 3 – Determining a Cards Score Write a function to return a card's score. int cardScore(int card) Returns a value between 2 and 11 as described in the rules. Recall that the score is the card's value except that aces are worth 11 and face cards are worth 10. The card parameter represents the card for which the score is to be determined.
Part 4 – Dealing Cards Now that you've completed Parts 1 and 2 you can write a function that handles dealing cards. int deal(bool isPlayer, bool isShown) This function is responsible for: 1. Generating the next card to be dealt (Part 1) 2. Printing out what card was dealt (Part 2) and to whom, if needed (see below) 3. Returning the card's score (Part 3) The two Boolean parameters are related to printing out the card. The isPlayer parameter is used to determine whether the word PLAYER or DEALER should be printed at the start of the output. The isShown parameter is used to determine if the card should be printed – recall that the second card dealt to the dealer is hidden.
MYCODE
#include
#include
#include
#include
using namespace std;
void displaycard(int card, int suits){
string cardtype[13] = { "Ace of", "Two of", "Three of" , "Four of" , "Five of" , "Six of", "Seven of","Eight of", "Nine of", "Ten of", "Jack of","Queen of","King of" };
cout << cardtype[card];
string suit[4]={" hearts"," diamonds"," spades"," clubs"};
cout << suit[suits];
}
int getcard(){
int card;
card = rand()%13;
return card;
}
int getsuit(){
int suits;
suits = rand() % 4;
return suits;
}
int cardScore(int card)
{
if (card == 11 || card == 12 || card == 13)
{
card = 10;
}
else if (card == 1)
{
card = 11;
}
else
{
card = card;
}
return card;
}
int deal(bool isPlayer, bool isShown){
int cardWhom;
int dealer;
if (cardWhom == true||dealer == true ){
cout << "PLAYER"<< endl;
}
else {
cout << "DEALER" << endl;
}
}
int main(){
srand((unsigned)time(0));
return 0;
}
#include<bits/stdc++.h>
using namespace std;
void displaycard(int card, int suits){
string cardtype[13] = { "Ace of", "Two of", "Three of" , "Four of" , "Five of" , "Six of", "Seven of","Eight of", "Nine of", "Ten of", "Jack of","Queen of","King of" };
cout << cardtype[card];
string suit[4]={" hearts"," diamonds"," spades"," clubs"};
cout << suit[suits];
}
int getcard(){
int card;
card = rand()%13;
return card;
}
int getsuit(){
int suits;
suits = rand() % 4;
return suits;
}
int cardScore(int card){
int score;
if (card == 10 || card == 11 || card == 12)
score = 10;
else if (card == 0)
score = 11;
else
score = card+1;
return score;
}
int deal(bool isPlayer, bool isShown){
int card = getcard();
int suit = getsuit();
if(isShown){
displaycard(card,suit);
}
if(isPlayer){
cout<<setw(16)<<"To Player"<<"\n";
}
else{
cout<<setw(16)<<"To Dealer"<<"\n";
}
cout<<"Card Score"<<setw(14)<<cardScore(card)<<"\n";
}
int main(){
srand((unsigned)time(0));
cout<<"Welcome to BlackJack"<<"\n";
bool startWithPlayer=true;
bool showPlayerCards = true;
bool showDealerCards = true;
while(1){
cout<<"\n";
cout<<"To deal press 1"<<"\n";
cout<<"To quit press 0"<<"\n";
int c;
cin>>c;
cout<<"\n";
switch(c){
case 1:{
if(startWithPlayer)
deal(startWithPlayer,showPlayerCards);
else
deal(startWithPlayer,showDealerCards);
startWithPlayer = startWithPlayer^1;
break;
}
case 0:{
cout<<"Thank you for the wonderful game"<<"\n";
return 0;
break;
}
default:{
cout<<"Please enter valid input"<<"\n";
break;
}
}
}
return 0;
}