BlackJack Game C++











up vote
0
down vote

favorite












I am new to coding with c++ and I am needing some advice about a code I am working on for a BlackJack game. So Far I have built my card and deck class for the blackjack game but I am finding it difficult to what I need to do to assign values to the cards.



This is what I have got so far



BlackJack.cpp



# include <iostream>
# include <string>
# include "Player.h"
# include "Card.h"
# include "CardDeck.h"

using namespace std;

int choice;
char choices;

Player player;

CardDeck deck1;

Card card1, card2, card3, card4, card5, card6, card7, card8, card9, card10;



void BlackJackwelcome();
void BlackJackmenu();
void BlackJackGame();

int main() {


string first;
string second;


BlackJackwelcome();
cout << "nFirst Name: ";
cin >> first;
player.setfirstName(first);

cout << "nSecond Name: ";
cin >> second;
player.setsecondName(second);

cout << "nHi there " + player.getName();
cout << "n" << endl;

cout << "Please choose from the menu below what you would like to do " + player.getName() << endl;

BlackJackmenu();





}

void BlackJackwelcome() {

cout << " ------------------------------------------------------- " << endl;
cout << " Welcome to BlackJack nnnn " << endl;
cout << " Please enter your First and Last Name down below " << endl;

}

void BlackJackmenu() {
cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "|| 1) Play BlackJack. ||" << endl;
cout << "|| 2) Rules of the Game. ||" << endl;
cout << "|| 3) Details of the Designer. ||" << endl;
cout << "|| 4) Exit the Game. ||" << endl;
cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cin >> choice;

if (choice == 1) {
cout << "Lets play BlackJack" << endl;

BlackJackGame();

}
else if (choice == 2) {
cout << "You have chosen to know the rules of BlackJack." << endl;
cout << "Press the 'Enter' Key to continue." << endl;
cin.get();
cin.get();
cout << " The rules of BlackJack are detailed below." << endl;
cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "|| Players try to make the highest value hand they can, up to a maximum of 21. ||" << endl;
cout << "|| Hands valued at 22 or more automatically lose – this is known as going bust. ||" << endl;
cout << "|| Players can usually stand when they want. In this game the dealer must stand on a soft 17. ||" << endl;
cout << "|| Hand value is determined by the numerical value of the cards in your hand. ||" << endl;
cout << "|| Numbered cards are assigned their number in points – 7s are worth 7 points, 3s are worth 3 points, and so on. ||" << endl;
cout << "||The high cards 10 - K are all worth 10 points, while Aces carry a value of 1 or 11, depending on the value of your hand at any time.||" << endl;
cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "Lets to go back to the main menu" << endl;
cout << "Press the 'Enter' key" << endl;
cin.get();
BlackJackmenu();

}
else if (choice == 3) {
cout << "You have chosen to read details of the game designer. Press Enter to continue" << endl;
cin.get();
cin.get();
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "|| Name of the designer is Ryan Fox. ||" << endl;
cout << "|| Game designed in December 2018. ||" << endl;
cout << "|| Designed for Coursework assignment COM 357 Object Oriented Programming. ||" << endl;
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "Lets to go back to the main menu" << endl;
cout << "Press the 'Enter' key" << endl;
cin.get();
BlackJackmenu();
}
else if (choice == 4) {
cout << "Thank you for playing. Good Bye." << endl;
}
else if (choice != 4) {


cout << "Sorry that number is not on the menu. Would you like to see the choices again?" << endl;
cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
cin >> choices;

if (choices == 'Y' || 'y') {
BlackJackmenu();
}
else if (choices == 'N' || 'n') {
cout << "Thanks for playing. Good Bye." << endl;
}
else {
cout << "Invalid choice. Start the program again please." << endl;

}

}


}

void BlackJackGame() {

const int win = 2;
const int Blackjack = 3;
const int GAMELIMIT = 21;
const int Dealer = 17;
int cardtotal1=0, cardtotal2=0;

cout << "Let's play BlackJack." << endl;
cout << "Before we start I am going to show you the deck." << endl;

deck1.printDeck();

cout << "After seeing the cards in the deck, whenever you are ready press the 'Enter' key to continue." << endl;
cin.get();
cin.get();

cout << "Firstly, let's shuffle the deck." << endl;
deck1.shuffle();

cout << "The cards have been shuffled. Press the 'Enter' to continue to dealing the cards.";
cin.get();
cin.get();

card1 = deck1.dealCard();
card2 = deck1.dealCard();
card3 = deck1.dealCard();

cout << "Players cards are: " << card1.toString() << " and " << card3.toString() << endl;
cardtotal1;
cout << "With these cards your total is: " << cardtotal1 << endl;


cout << "Dealer has " << card2.toString() << " and ****" << endl;






cout << "Would you like to play again?" << endl;
cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
cin >> choices;

switch (choices) {

case 'Y':
case 'y':
BlackJackGame();
break;
case 'N':
case 'n': cout << "Thanks for playing. Goodbye." << endl;
break;
default: cout << "You didn't enter any of the choices needed to proceed. Please enter Y/y for YES or N/n for NO.n";
}
return;


}


Card .h



# include <iostream>
# include <string>
# include <array>

# ifndef CARD_H
# define CARD_H

using namespace std;



class Card
{
public:

Card(int = 0, int = 0, int = 0);

int getSuit();
int getFace();
int getValue();

void setFace(int);
void setSuit(int);
void setValue(int);

string toString();

static const array<string, 4> suits;
static const array<string, 14> faces;
static const array<int, 14> values;

private:

int face;
int suit;
int value;


};

# endif


Card.cpp



#include "Card.h"

using namespace std;

const array<string, 14> Card::faces{ "ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "ACE" };

const array<string, 4> Card::suits{ "Hearts", "Diamonds", "Spades", "Clubs" };

const array<int, 14> Card::values{ 1,2,3,4,5,6,7,8,9,10,10,10,10,11 };


Card::Card(int cardt1, int cardt2, int v1){
face = cardt1;
suit = cardt2;
value = v1;

}

int Card::getFace() {

return face;
}

int Card::getSuit() {

return suit;

}

int Card::getValue() {

return value;
}

void Card::setSuit(int cardt2){

suit = cardt2;

}

void Card::setFace(int cardt1) {

face = cardt1;
}

void Card::setValue(int v1) {

value = v1;
}

string Card::toString() {

return (faces[face] + " of " + suits[suit]);

}

CardDeck.h

# ifndef CARDDECK_H
# define CARDDECK_H

# include <iostream>
# include "Card.h"
# include <vector>

class CardDeck {


public:
CardDeck();
void shuffle();

Card dealCard();
bool moveCard();

void printDeck();

private:
vector<Card> deck;
int currentCard;

};

#endif

CardDeck.cpp
# include <iostream>
# include <ctime>
# include <string>
# include "Player.h"
# include "Card.h"
# include "CardDeck.h"

using namespace std;

int choice;
char choices;

Player player;

CardDeck deck1;

Card card1, card2, card3, card4, card5, card6, card7, card8, card9, card10;



void BlackJackwelcome();
void BlackJackmenu();
void BlackJackGame();

int main() {


string first;
string second;


BlackJackwelcome();
cout << "nFirst Name: ";
cin >> first;
player.setfirstName(first);

cout << "nSecond Name: ";
cin >> second;
player.setsecondName(second);

cout << "nHi there " + player.getName();
cout << "n" << endl;

cout << "Please choose from the menu below what you would like to do " + player.getName() << endl;

BlackJackmenu();





}

void BlackJackwelcome() {

cout << " ------------------------------------------------------- " << endl;
cout << " Welcome to BlackJack nnnn " << endl;
cout << " Please enter your First and Last Name down below " << endl;

}

void BlackJackmenu() {
cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "|| 1) Play BlackJack. ||" << endl;
cout << "|| 2) Rules of the Game. ||" << endl;
cout << "|| 3) Details of the Designer. ||" << endl;
cout << "|| 4) Exit the Game. ||" << endl;
cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cin >> choice;

if (choice == 1) {
cout << "Lets play BlackJack" << endl;

BlackJackGame();

}
else if (choice == 2) {
cout << "You have chosen to know the rules of BlackJack." << endl;
cout << "Press the 'Enter' Key to continue." << endl;
cin.get();
cin.get();
cout << " The rules of BlackJack are detailed below." << endl;
cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "|| Players try to make the highest value hand they can, up to a maximum of 21. ||" << endl;
cout << "|| Hands valued at 22 or more automatically lose – this is known as going bust. ||" << endl;
cout << "|| Players can usually stand when they want. In this game the dealer must stand on a soft 17. ||" << endl;
cout << "|| Hand value is determined by the numerical value of the cards in your hand. ||" << endl;
cout << "|| Numbered cards are assigned their number in points – 7s are worth 7 points, 3s are worth 3 points, and so on. ||" << endl;
cout << "||The high cards 10 - K are all worth 10 points, while Aces carry a value of 1 or 11, depending on the value of your hand at any time.||" << endl;
cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "Lets to go back to the main menu" << endl;
cout << "Press the 'Enter' key" << endl;
cin.get();
BlackJackmenu();

}
else if (choice == 3) {
cout << "You have chosen to read details of the game designer. Press Enter to continue" << endl;
cin.get();
cin.get();
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "|| Name of the designer is Ryan Fox. ||" << endl;
cout << "|| Game designed in December 2018. ||" << endl;
cout << "|| Designed for Coursework assignment COM 357 Object Oriented Programming. ||" << endl;
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "Lets to go back to the main menu" << endl;
cout << "Press the 'Enter' key" << endl;
cin.get();
BlackJackmenu();
}
else if (choice == 4) {
cout << "Thank you for playing. Good Bye." << endl;
}
else if (choice != 4) {


cout << "Sorry that number is not on the menu. Would you like to see the choices again?" << endl;
cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
cin >> choices;

if (choices == 'Y' || 'y') {
BlackJackmenu();
}
else if (choices == 'N' || 'n') {
cout << "Thanks for playing. Good Bye." << endl;
}
else {
cout << "Invalid choice. Start the program again please." << endl;

}

}


}

void BlackJackGame() {

const int win = 2;
const int Blackjack = 3;
const int GAMELIMIT = 21;
const int Dealer = 17;
int cardtotal1=0, cardtotal2=0;

cout << "Let's play BlackJack." << endl;
cout << "Before we start I am going to show you the deck." << endl;

deck1.printDeck();

cout << "After seeing the cards in the deck, whenever you are ready press the 'Enter' key to continue." << endl;
cin.get();
cin.get();

cout << "Firstly, let's shuffle the deck." << endl;
deck1.shuffle();

cout << "The cards have been shuffled. Press the 'Enter' to continue to dealing the cards.";
cin.get();
cin.get();

card1 = deck1.dealCard();
card2 = deck1.dealCard();
card3 = deck1.dealCard();

cout << "Players cards are: " << card1.toString() << " and " << card3.toString() << endl;
cardtotal1;
cout << "With these cards your total is: " << cardtotal1 << endl;


cout << "Dealer has " << card2.toString() << " and ****" << endl;






cout << "Would you like to play again?" << endl;
cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
cin >> choices;

switch (choices) {

case 'Y':
case 'y':
BlackJackGame();
break;
case 'N':
case 'n': cout << "Thanks for playing. Goodbye." << endl;
break;
default: cout << "You didn't enter any of the choices needed to proceed. Please enter Y/y for YES or N/n for NO.n";
}
return;


}


If you can give me any help or advice I would be thankful. I have a feeling it may be the vectors being string values but just want to know I am going in the right direction









share







New contributor




foxy1000000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote

    favorite












    I am new to coding with c++ and I am needing some advice about a code I am working on for a BlackJack game. So Far I have built my card and deck class for the blackjack game but I am finding it difficult to what I need to do to assign values to the cards.



    This is what I have got so far



    BlackJack.cpp



    # include <iostream>
    # include <string>
    # include "Player.h"
    # include "Card.h"
    # include "CardDeck.h"

    using namespace std;

    int choice;
    char choices;

    Player player;

    CardDeck deck1;

    Card card1, card2, card3, card4, card5, card6, card7, card8, card9, card10;



    void BlackJackwelcome();
    void BlackJackmenu();
    void BlackJackGame();

    int main() {


    string first;
    string second;


    BlackJackwelcome();
    cout << "nFirst Name: ";
    cin >> first;
    player.setfirstName(first);

    cout << "nSecond Name: ";
    cin >> second;
    player.setsecondName(second);

    cout << "nHi there " + player.getName();
    cout << "n" << endl;

    cout << "Please choose from the menu below what you would like to do " + player.getName() << endl;

    BlackJackmenu();





    }

    void BlackJackwelcome() {

    cout << " ------------------------------------------------------- " << endl;
    cout << " Welcome to BlackJack nnnn " << endl;
    cout << " Please enter your First and Last Name down below " << endl;

    }

    void BlackJackmenu() {
    cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cout << "|| 1) Play BlackJack. ||" << endl;
    cout << "|| 2) Rules of the Game. ||" << endl;
    cout << "|| 3) Details of the Designer. ||" << endl;
    cout << "|| 4) Exit the Game. ||" << endl;
    cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cin >> choice;

    if (choice == 1) {
    cout << "Lets play BlackJack" << endl;

    BlackJackGame();

    }
    else if (choice == 2) {
    cout << "You have chosen to know the rules of BlackJack." << endl;
    cout << "Press the 'Enter' Key to continue." << endl;
    cin.get();
    cin.get();
    cout << " The rules of BlackJack are detailed below." << endl;
    cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cout << "|| Players try to make the highest value hand they can, up to a maximum of 21. ||" << endl;
    cout << "|| Hands valued at 22 or more automatically lose – this is known as going bust. ||" << endl;
    cout << "|| Players can usually stand when they want. In this game the dealer must stand on a soft 17. ||" << endl;
    cout << "|| Hand value is determined by the numerical value of the cards in your hand. ||" << endl;
    cout << "|| Numbered cards are assigned their number in points – 7s are worth 7 points, 3s are worth 3 points, and so on. ||" << endl;
    cout << "||The high cards 10 - K are all worth 10 points, while Aces carry a value of 1 or 11, depending on the value of your hand at any time.||" << endl;
    cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cout << "Lets to go back to the main menu" << endl;
    cout << "Press the 'Enter' key" << endl;
    cin.get();
    BlackJackmenu();

    }
    else if (choice == 3) {
    cout << "You have chosen to read details of the game designer. Press Enter to continue" << endl;
    cin.get();
    cin.get();
    cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cout << "|| Name of the designer is Ryan Fox. ||" << endl;
    cout << "|| Game designed in December 2018. ||" << endl;
    cout << "|| Designed for Coursework assignment COM 357 Object Oriented Programming. ||" << endl;
    cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cout << "Lets to go back to the main menu" << endl;
    cout << "Press the 'Enter' key" << endl;
    cin.get();
    BlackJackmenu();
    }
    else if (choice == 4) {
    cout << "Thank you for playing. Good Bye." << endl;
    }
    else if (choice != 4) {


    cout << "Sorry that number is not on the menu. Would you like to see the choices again?" << endl;
    cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
    cin >> choices;

    if (choices == 'Y' || 'y') {
    BlackJackmenu();
    }
    else if (choices == 'N' || 'n') {
    cout << "Thanks for playing. Good Bye." << endl;
    }
    else {
    cout << "Invalid choice. Start the program again please." << endl;

    }

    }


    }

    void BlackJackGame() {

    const int win = 2;
    const int Blackjack = 3;
    const int GAMELIMIT = 21;
    const int Dealer = 17;
    int cardtotal1=0, cardtotal2=0;

    cout << "Let's play BlackJack." << endl;
    cout << "Before we start I am going to show you the deck." << endl;

    deck1.printDeck();

    cout << "After seeing the cards in the deck, whenever you are ready press the 'Enter' key to continue." << endl;
    cin.get();
    cin.get();

    cout << "Firstly, let's shuffle the deck." << endl;
    deck1.shuffle();

    cout << "The cards have been shuffled. Press the 'Enter' to continue to dealing the cards.";
    cin.get();
    cin.get();

    card1 = deck1.dealCard();
    card2 = deck1.dealCard();
    card3 = deck1.dealCard();

    cout << "Players cards are: " << card1.toString() << " and " << card3.toString() << endl;
    cardtotal1;
    cout << "With these cards your total is: " << cardtotal1 << endl;


    cout << "Dealer has " << card2.toString() << " and ****" << endl;






    cout << "Would you like to play again?" << endl;
    cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
    cin >> choices;

    switch (choices) {

    case 'Y':
    case 'y':
    BlackJackGame();
    break;
    case 'N':
    case 'n': cout << "Thanks for playing. Goodbye." << endl;
    break;
    default: cout << "You didn't enter any of the choices needed to proceed. Please enter Y/y for YES or N/n for NO.n";
    }
    return;


    }


    Card .h



    # include <iostream>
    # include <string>
    # include <array>

    # ifndef CARD_H
    # define CARD_H

    using namespace std;



    class Card
    {
    public:

    Card(int = 0, int = 0, int = 0);

    int getSuit();
    int getFace();
    int getValue();

    void setFace(int);
    void setSuit(int);
    void setValue(int);

    string toString();

    static const array<string, 4> suits;
    static const array<string, 14> faces;
    static const array<int, 14> values;

    private:

    int face;
    int suit;
    int value;


    };

    # endif


    Card.cpp



    #include "Card.h"

    using namespace std;

    const array<string, 14> Card::faces{ "ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "ACE" };

    const array<string, 4> Card::suits{ "Hearts", "Diamonds", "Spades", "Clubs" };

    const array<int, 14> Card::values{ 1,2,3,4,5,6,7,8,9,10,10,10,10,11 };


    Card::Card(int cardt1, int cardt2, int v1){
    face = cardt1;
    suit = cardt2;
    value = v1;

    }

    int Card::getFace() {

    return face;
    }

    int Card::getSuit() {

    return suit;

    }

    int Card::getValue() {

    return value;
    }

    void Card::setSuit(int cardt2){

    suit = cardt2;

    }

    void Card::setFace(int cardt1) {

    face = cardt1;
    }

    void Card::setValue(int v1) {

    value = v1;
    }

    string Card::toString() {

    return (faces[face] + " of " + suits[suit]);

    }

    CardDeck.h

    # ifndef CARDDECK_H
    # define CARDDECK_H

    # include <iostream>
    # include "Card.h"
    # include <vector>

    class CardDeck {


    public:
    CardDeck();
    void shuffle();

    Card dealCard();
    bool moveCard();

    void printDeck();

    private:
    vector<Card> deck;
    int currentCard;

    };

    #endif

    CardDeck.cpp
    # include <iostream>
    # include <ctime>
    # include <string>
    # include "Player.h"
    # include "Card.h"
    # include "CardDeck.h"

    using namespace std;

    int choice;
    char choices;

    Player player;

    CardDeck deck1;

    Card card1, card2, card3, card4, card5, card6, card7, card8, card9, card10;



    void BlackJackwelcome();
    void BlackJackmenu();
    void BlackJackGame();

    int main() {


    string first;
    string second;


    BlackJackwelcome();
    cout << "nFirst Name: ";
    cin >> first;
    player.setfirstName(first);

    cout << "nSecond Name: ";
    cin >> second;
    player.setsecondName(second);

    cout << "nHi there " + player.getName();
    cout << "n" << endl;

    cout << "Please choose from the menu below what you would like to do " + player.getName() << endl;

    BlackJackmenu();





    }

    void BlackJackwelcome() {

    cout << " ------------------------------------------------------- " << endl;
    cout << " Welcome to BlackJack nnnn " << endl;
    cout << " Please enter your First and Last Name down below " << endl;

    }

    void BlackJackmenu() {
    cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cout << "|| 1) Play BlackJack. ||" << endl;
    cout << "|| 2) Rules of the Game. ||" << endl;
    cout << "|| 3) Details of the Designer. ||" << endl;
    cout << "|| 4) Exit the Game. ||" << endl;
    cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cin >> choice;

    if (choice == 1) {
    cout << "Lets play BlackJack" << endl;

    BlackJackGame();

    }
    else if (choice == 2) {
    cout << "You have chosen to know the rules of BlackJack." << endl;
    cout << "Press the 'Enter' Key to continue." << endl;
    cin.get();
    cin.get();
    cout << " The rules of BlackJack are detailed below." << endl;
    cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cout << "|| Players try to make the highest value hand they can, up to a maximum of 21. ||" << endl;
    cout << "|| Hands valued at 22 or more automatically lose – this is known as going bust. ||" << endl;
    cout << "|| Players can usually stand when they want. In this game the dealer must stand on a soft 17. ||" << endl;
    cout << "|| Hand value is determined by the numerical value of the cards in your hand. ||" << endl;
    cout << "|| Numbered cards are assigned their number in points – 7s are worth 7 points, 3s are worth 3 points, and so on. ||" << endl;
    cout << "||The high cards 10 - K are all worth 10 points, while Aces carry a value of 1 or 11, depending on the value of your hand at any time.||" << endl;
    cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cout << "Lets to go back to the main menu" << endl;
    cout << "Press the 'Enter' key" << endl;
    cin.get();
    BlackJackmenu();

    }
    else if (choice == 3) {
    cout << "You have chosen to read details of the game designer. Press Enter to continue" << endl;
    cin.get();
    cin.get();
    cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cout << "|| Name of the designer is Ryan Fox. ||" << endl;
    cout << "|| Game designed in December 2018. ||" << endl;
    cout << "|| Designed for Coursework assignment COM 357 Object Oriented Programming. ||" << endl;
    cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
    cout << "Lets to go back to the main menu" << endl;
    cout << "Press the 'Enter' key" << endl;
    cin.get();
    BlackJackmenu();
    }
    else if (choice == 4) {
    cout << "Thank you for playing. Good Bye." << endl;
    }
    else if (choice != 4) {


    cout << "Sorry that number is not on the menu. Would you like to see the choices again?" << endl;
    cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
    cin >> choices;

    if (choices == 'Y' || 'y') {
    BlackJackmenu();
    }
    else if (choices == 'N' || 'n') {
    cout << "Thanks for playing. Good Bye." << endl;
    }
    else {
    cout << "Invalid choice. Start the program again please." << endl;

    }

    }


    }

    void BlackJackGame() {

    const int win = 2;
    const int Blackjack = 3;
    const int GAMELIMIT = 21;
    const int Dealer = 17;
    int cardtotal1=0, cardtotal2=0;

    cout << "Let's play BlackJack." << endl;
    cout << "Before we start I am going to show you the deck." << endl;

    deck1.printDeck();

    cout << "After seeing the cards in the deck, whenever you are ready press the 'Enter' key to continue." << endl;
    cin.get();
    cin.get();

    cout << "Firstly, let's shuffle the deck." << endl;
    deck1.shuffle();

    cout << "The cards have been shuffled. Press the 'Enter' to continue to dealing the cards.";
    cin.get();
    cin.get();

    card1 = deck1.dealCard();
    card2 = deck1.dealCard();
    card3 = deck1.dealCard();

    cout << "Players cards are: " << card1.toString() << " and " << card3.toString() << endl;
    cardtotal1;
    cout << "With these cards your total is: " << cardtotal1 << endl;


    cout << "Dealer has " << card2.toString() << " and ****" << endl;






    cout << "Would you like to play again?" << endl;
    cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
    cin >> choices;

    switch (choices) {

    case 'Y':
    case 'y':
    BlackJackGame();
    break;
    case 'N':
    case 'n': cout << "Thanks for playing. Goodbye." << endl;
    break;
    default: cout << "You didn't enter any of the choices needed to proceed. Please enter Y/y for YES or N/n for NO.n";
    }
    return;


    }


    If you can give me any help or advice I would be thankful. I have a feeling it may be the vectors being string values but just want to know I am going in the right direction









    share







    New contributor




    foxy1000000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am new to coding with c++ and I am needing some advice about a code I am working on for a BlackJack game. So Far I have built my card and deck class for the blackjack game but I am finding it difficult to what I need to do to assign values to the cards.



      This is what I have got so far



      BlackJack.cpp



      # include <iostream>
      # include <string>
      # include "Player.h"
      # include "Card.h"
      # include "CardDeck.h"

      using namespace std;

      int choice;
      char choices;

      Player player;

      CardDeck deck1;

      Card card1, card2, card3, card4, card5, card6, card7, card8, card9, card10;



      void BlackJackwelcome();
      void BlackJackmenu();
      void BlackJackGame();

      int main() {


      string first;
      string second;


      BlackJackwelcome();
      cout << "nFirst Name: ";
      cin >> first;
      player.setfirstName(first);

      cout << "nSecond Name: ";
      cin >> second;
      player.setsecondName(second);

      cout << "nHi there " + player.getName();
      cout << "n" << endl;

      cout << "Please choose from the menu below what you would like to do " + player.getName() << endl;

      BlackJackmenu();





      }

      void BlackJackwelcome() {

      cout << " ------------------------------------------------------- " << endl;
      cout << " Welcome to BlackJack nnnn " << endl;
      cout << " Please enter your First and Last Name down below " << endl;

      }

      void BlackJackmenu() {
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| 1) Play BlackJack. ||" << endl;
      cout << "|| 2) Rules of the Game. ||" << endl;
      cout << "|| 3) Details of the Designer. ||" << endl;
      cout << "|| 4) Exit the Game. ||" << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cin >> choice;

      if (choice == 1) {
      cout << "Lets play BlackJack" << endl;

      BlackJackGame();

      }
      else if (choice == 2) {
      cout << "You have chosen to know the rules of BlackJack." << endl;
      cout << "Press the 'Enter' Key to continue." << endl;
      cin.get();
      cin.get();
      cout << " The rules of BlackJack are detailed below." << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| Players try to make the highest value hand they can, up to a maximum of 21. ||" << endl;
      cout << "|| Hands valued at 22 or more automatically lose – this is known as going bust. ||" << endl;
      cout << "|| Players can usually stand when they want. In this game the dealer must stand on a soft 17. ||" << endl;
      cout << "|| Hand value is determined by the numerical value of the cards in your hand. ||" << endl;
      cout << "|| Numbered cards are assigned their number in points – 7s are worth 7 points, 3s are worth 3 points, and so on. ||" << endl;
      cout << "||The high cards 10 - K are all worth 10 points, while Aces carry a value of 1 or 11, depending on the value of your hand at any time.||" << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "Lets to go back to the main menu" << endl;
      cout << "Press the 'Enter' key" << endl;
      cin.get();
      BlackJackmenu();

      }
      else if (choice == 3) {
      cout << "You have chosen to read details of the game designer. Press Enter to continue" << endl;
      cin.get();
      cin.get();
      cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| Name of the designer is Ryan Fox. ||" << endl;
      cout << "|| Game designed in December 2018. ||" << endl;
      cout << "|| Designed for Coursework assignment COM 357 Object Oriented Programming. ||" << endl;
      cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "Lets to go back to the main menu" << endl;
      cout << "Press the 'Enter' key" << endl;
      cin.get();
      BlackJackmenu();
      }
      else if (choice == 4) {
      cout << "Thank you for playing. Good Bye." << endl;
      }
      else if (choice != 4) {


      cout << "Sorry that number is not on the menu. Would you like to see the choices again?" << endl;
      cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
      cin >> choices;

      if (choices == 'Y' || 'y') {
      BlackJackmenu();
      }
      else if (choices == 'N' || 'n') {
      cout << "Thanks for playing. Good Bye." << endl;
      }
      else {
      cout << "Invalid choice. Start the program again please." << endl;

      }

      }


      }

      void BlackJackGame() {

      const int win = 2;
      const int Blackjack = 3;
      const int GAMELIMIT = 21;
      const int Dealer = 17;
      int cardtotal1=0, cardtotal2=0;

      cout << "Let's play BlackJack." << endl;
      cout << "Before we start I am going to show you the deck." << endl;

      deck1.printDeck();

      cout << "After seeing the cards in the deck, whenever you are ready press the 'Enter' key to continue." << endl;
      cin.get();
      cin.get();

      cout << "Firstly, let's shuffle the deck." << endl;
      deck1.shuffle();

      cout << "The cards have been shuffled. Press the 'Enter' to continue to dealing the cards.";
      cin.get();
      cin.get();

      card1 = deck1.dealCard();
      card2 = deck1.dealCard();
      card3 = deck1.dealCard();

      cout << "Players cards are: " << card1.toString() << " and " << card3.toString() << endl;
      cardtotal1;
      cout << "With these cards your total is: " << cardtotal1 << endl;


      cout << "Dealer has " << card2.toString() << " and ****" << endl;






      cout << "Would you like to play again?" << endl;
      cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
      cin >> choices;

      switch (choices) {

      case 'Y':
      case 'y':
      BlackJackGame();
      break;
      case 'N':
      case 'n': cout << "Thanks for playing. Goodbye." << endl;
      break;
      default: cout << "You didn't enter any of the choices needed to proceed. Please enter Y/y for YES or N/n for NO.n";
      }
      return;


      }


      Card .h



      # include <iostream>
      # include <string>
      # include <array>

      # ifndef CARD_H
      # define CARD_H

      using namespace std;



      class Card
      {
      public:

      Card(int = 0, int = 0, int = 0);

      int getSuit();
      int getFace();
      int getValue();

      void setFace(int);
      void setSuit(int);
      void setValue(int);

      string toString();

      static const array<string, 4> suits;
      static const array<string, 14> faces;
      static const array<int, 14> values;

      private:

      int face;
      int suit;
      int value;


      };

      # endif


      Card.cpp



      #include "Card.h"

      using namespace std;

      const array<string, 14> Card::faces{ "ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "ACE" };

      const array<string, 4> Card::suits{ "Hearts", "Diamonds", "Spades", "Clubs" };

      const array<int, 14> Card::values{ 1,2,3,4,5,6,7,8,9,10,10,10,10,11 };


      Card::Card(int cardt1, int cardt2, int v1){
      face = cardt1;
      suit = cardt2;
      value = v1;

      }

      int Card::getFace() {

      return face;
      }

      int Card::getSuit() {

      return suit;

      }

      int Card::getValue() {

      return value;
      }

      void Card::setSuit(int cardt2){

      suit = cardt2;

      }

      void Card::setFace(int cardt1) {

      face = cardt1;
      }

      void Card::setValue(int v1) {

      value = v1;
      }

      string Card::toString() {

      return (faces[face] + " of " + suits[suit]);

      }

      CardDeck.h

      # ifndef CARDDECK_H
      # define CARDDECK_H

      # include <iostream>
      # include "Card.h"
      # include <vector>

      class CardDeck {


      public:
      CardDeck();
      void shuffle();

      Card dealCard();
      bool moveCard();

      void printDeck();

      private:
      vector<Card> deck;
      int currentCard;

      };

      #endif

      CardDeck.cpp
      # include <iostream>
      # include <ctime>
      # include <string>
      # include "Player.h"
      # include "Card.h"
      # include "CardDeck.h"

      using namespace std;

      int choice;
      char choices;

      Player player;

      CardDeck deck1;

      Card card1, card2, card3, card4, card5, card6, card7, card8, card9, card10;



      void BlackJackwelcome();
      void BlackJackmenu();
      void BlackJackGame();

      int main() {


      string first;
      string second;


      BlackJackwelcome();
      cout << "nFirst Name: ";
      cin >> first;
      player.setfirstName(first);

      cout << "nSecond Name: ";
      cin >> second;
      player.setsecondName(second);

      cout << "nHi there " + player.getName();
      cout << "n" << endl;

      cout << "Please choose from the menu below what you would like to do " + player.getName() << endl;

      BlackJackmenu();





      }

      void BlackJackwelcome() {

      cout << " ------------------------------------------------------- " << endl;
      cout << " Welcome to BlackJack nnnn " << endl;
      cout << " Please enter your First and Last Name down below " << endl;

      }

      void BlackJackmenu() {
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| 1) Play BlackJack. ||" << endl;
      cout << "|| 2) Rules of the Game. ||" << endl;
      cout << "|| 3) Details of the Designer. ||" << endl;
      cout << "|| 4) Exit the Game. ||" << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cin >> choice;

      if (choice == 1) {
      cout << "Lets play BlackJack" << endl;

      BlackJackGame();

      }
      else if (choice == 2) {
      cout << "You have chosen to know the rules of BlackJack." << endl;
      cout << "Press the 'Enter' Key to continue." << endl;
      cin.get();
      cin.get();
      cout << " The rules of BlackJack are detailed below." << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| Players try to make the highest value hand they can, up to a maximum of 21. ||" << endl;
      cout << "|| Hands valued at 22 or more automatically lose – this is known as going bust. ||" << endl;
      cout << "|| Players can usually stand when they want. In this game the dealer must stand on a soft 17. ||" << endl;
      cout << "|| Hand value is determined by the numerical value of the cards in your hand. ||" << endl;
      cout << "|| Numbered cards are assigned their number in points – 7s are worth 7 points, 3s are worth 3 points, and so on. ||" << endl;
      cout << "||The high cards 10 - K are all worth 10 points, while Aces carry a value of 1 or 11, depending on the value of your hand at any time.||" << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "Lets to go back to the main menu" << endl;
      cout << "Press the 'Enter' key" << endl;
      cin.get();
      BlackJackmenu();

      }
      else if (choice == 3) {
      cout << "You have chosen to read details of the game designer. Press Enter to continue" << endl;
      cin.get();
      cin.get();
      cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| Name of the designer is Ryan Fox. ||" << endl;
      cout << "|| Game designed in December 2018. ||" << endl;
      cout << "|| Designed for Coursework assignment COM 357 Object Oriented Programming. ||" << endl;
      cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "Lets to go back to the main menu" << endl;
      cout << "Press the 'Enter' key" << endl;
      cin.get();
      BlackJackmenu();
      }
      else if (choice == 4) {
      cout << "Thank you for playing. Good Bye." << endl;
      }
      else if (choice != 4) {


      cout << "Sorry that number is not on the menu. Would you like to see the choices again?" << endl;
      cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
      cin >> choices;

      if (choices == 'Y' || 'y') {
      BlackJackmenu();
      }
      else if (choices == 'N' || 'n') {
      cout << "Thanks for playing. Good Bye." << endl;
      }
      else {
      cout << "Invalid choice. Start the program again please." << endl;

      }

      }


      }

      void BlackJackGame() {

      const int win = 2;
      const int Blackjack = 3;
      const int GAMELIMIT = 21;
      const int Dealer = 17;
      int cardtotal1=0, cardtotal2=0;

      cout << "Let's play BlackJack." << endl;
      cout << "Before we start I am going to show you the deck." << endl;

      deck1.printDeck();

      cout << "After seeing the cards in the deck, whenever you are ready press the 'Enter' key to continue." << endl;
      cin.get();
      cin.get();

      cout << "Firstly, let's shuffle the deck." << endl;
      deck1.shuffle();

      cout << "The cards have been shuffled. Press the 'Enter' to continue to dealing the cards.";
      cin.get();
      cin.get();

      card1 = deck1.dealCard();
      card2 = deck1.dealCard();
      card3 = deck1.dealCard();

      cout << "Players cards are: " << card1.toString() << " and " << card3.toString() << endl;
      cardtotal1;
      cout << "With these cards your total is: " << cardtotal1 << endl;


      cout << "Dealer has " << card2.toString() << " and ****" << endl;






      cout << "Would you like to play again?" << endl;
      cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
      cin >> choices;

      switch (choices) {

      case 'Y':
      case 'y':
      BlackJackGame();
      break;
      case 'N':
      case 'n': cout << "Thanks for playing. Goodbye." << endl;
      break;
      default: cout << "You didn't enter any of the choices needed to proceed. Please enter Y/y for YES or N/n for NO.n";
      }
      return;


      }


      If you can give me any help or advice I would be thankful. I have a feeling it may be the vectors being string values but just want to know I am going in the right direction









      share







      New contributor




      foxy1000000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am new to coding with c++ and I am needing some advice about a code I am working on for a BlackJack game. So Far I have built my card and deck class for the blackjack game but I am finding it difficult to what I need to do to assign values to the cards.



      This is what I have got so far



      BlackJack.cpp



      # include <iostream>
      # include <string>
      # include "Player.h"
      # include "Card.h"
      # include "CardDeck.h"

      using namespace std;

      int choice;
      char choices;

      Player player;

      CardDeck deck1;

      Card card1, card2, card3, card4, card5, card6, card7, card8, card9, card10;



      void BlackJackwelcome();
      void BlackJackmenu();
      void BlackJackGame();

      int main() {


      string first;
      string second;


      BlackJackwelcome();
      cout << "nFirst Name: ";
      cin >> first;
      player.setfirstName(first);

      cout << "nSecond Name: ";
      cin >> second;
      player.setsecondName(second);

      cout << "nHi there " + player.getName();
      cout << "n" << endl;

      cout << "Please choose from the menu below what you would like to do " + player.getName() << endl;

      BlackJackmenu();





      }

      void BlackJackwelcome() {

      cout << " ------------------------------------------------------- " << endl;
      cout << " Welcome to BlackJack nnnn " << endl;
      cout << " Please enter your First and Last Name down below " << endl;

      }

      void BlackJackmenu() {
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| 1) Play BlackJack. ||" << endl;
      cout << "|| 2) Rules of the Game. ||" << endl;
      cout << "|| 3) Details of the Designer. ||" << endl;
      cout << "|| 4) Exit the Game. ||" << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cin >> choice;

      if (choice == 1) {
      cout << "Lets play BlackJack" << endl;

      BlackJackGame();

      }
      else if (choice == 2) {
      cout << "You have chosen to know the rules of BlackJack." << endl;
      cout << "Press the 'Enter' Key to continue." << endl;
      cin.get();
      cin.get();
      cout << " The rules of BlackJack are detailed below." << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| Players try to make the highest value hand they can, up to a maximum of 21. ||" << endl;
      cout << "|| Hands valued at 22 or more automatically lose – this is known as going bust. ||" << endl;
      cout << "|| Players can usually stand when they want. In this game the dealer must stand on a soft 17. ||" << endl;
      cout << "|| Hand value is determined by the numerical value of the cards in your hand. ||" << endl;
      cout << "|| Numbered cards are assigned their number in points – 7s are worth 7 points, 3s are worth 3 points, and so on. ||" << endl;
      cout << "||The high cards 10 - K are all worth 10 points, while Aces carry a value of 1 or 11, depending on the value of your hand at any time.||" << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "Lets to go back to the main menu" << endl;
      cout << "Press the 'Enter' key" << endl;
      cin.get();
      BlackJackmenu();

      }
      else if (choice == 3) {
      cout << "You have chosen to read details of the game designer. Press Enter to continue" << endl;
      cin.get();
      cin.get();
      cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| Name of the designer is Ryan Fox. ||" << endl;
      cout << "|| Game designed in December 2018. ||" << endl;
      cout << "|| Designed for Coursework assignment COM 357 Object Oriented Programming. ||" << endl;
      cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "Lets to go back to the main menu" << endl;
      cout << "Press the 'Enter' key" << endl;
      cin.get();
      BlackJackmenu();
      }
      else if (choice == 4) {
      cout << "Thank you for playing. Good Bye." << endl;
      }
      else if (choice != 4) {


      cout << "Sorry that number is not on the menu. Would you like to see the choices again?" << endl;
      cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
      cin >> choices;

      if (choices == 'Y' || 'y') {
      BlackJackmenu();
      }
      else if (choices == 'N' || 'n') {
      cout << "Thanks for playing. Good Bye." << endl;
      }
      else {
      cout << "Invalid choice. Start the program again please." << endl;

      }

      }


      }

      void BlackJackGame() {

      const int win = 2;
      const int Blackjack = 3;
      const int GAMELIMIT = 21;
      const int Dealer = 17;
      int cardtotal1=0, cardtotal2=0;

      cout << "Let's play BlackJack." << endl;
      cout << "Before we start I am going to show you the deck." << endl;

      deck1.printDeck();

      cout << "After seeing the cards in the deck, whenever you are ready press the 'Enter' key to continue." << endl;
      cin.get();
      cin.get();

      cout << "Firstly, let's shuffle the deck." << endl;
      deck1.shuffle();

      cout << "The cards have been shuffled. Press the 'Enter' to continue to dealing the cards.";
      cin.get();
      cin.get();

      card1 = deck1.dealCard();
      card2 = deck1.dealCard();
      card3 = deck1.dealCard();

      cout << "Players cards are: " << card1.toString() << " and " << card3.toString() << endl;
      cardtotal1;
      cout << "With these cards your total is: " << cardtotal1 << endl;


      cout << "Dealer has " << card2.toString() << " and ****" << endl;






      cout << "Would you like to play again?" << endl;
      cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
      cin >> choices;

      switch (choices) {

      case 'Y':
      case 'y':
      BlackJackGame();
      break;
      case 'N':
      case 'n': cout << "Thanks for playing. Goodbye." << endl;
      break;
      default: cout << "You didn't enter any of the choices needed to proceed. Please enter Y/y for YES or N/n for NO.n";
      }
      return;


      }


      Card .h



      # include <iostream>
      # include <string>
      # include <array>

      # ifndef CARD_H
      # define CARD_H

      using namespace std;



      class Card
      {
      public:

      Card(int = 0, int = 0, int = 0);

      int getSuit();
      int getFace();
      int getValue();

      void setFace(int);
      void setSuit(int);
      void setValue(int);

      string toString();

      static const array<string, 4> suits;
      static const array<string, 14> faces;
      static const array<int, 14> values;

      private:

      int face;
      int suit;
      int value;


      };

      # endif


      Card.cpp



      #include "Card.h"

      using namespace std;

      const array<string, 14> Card::faces{ "ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "ACE" };

      const array<string, 4> Card::suits{ "Hearts", "Diamonds", "Spades", "Clubs" };

      const array<int, 14> Card::values{ 1,2,3,4,5,6,7,8,9,10,10,10,10,11 };


      Card::Card(int cardt1, int cardt2, int v1){
      face = cardt1;
      suit = cardt2;
      value = v1;

      }

      int Card::getFace() {

      return face;
      }

      int Card::getSuit() {

      return suit;

      }

      int Card::getValue() {

      return value;
      }

      void Card::setSuit(int cardt2){

      suit = cardt2;

      }

      void Card::setFace(int cardt1) {

      face = cardt1;
      }

      void Card::setValue(int v1) {

      value = v1;
      }

      string Card::toString() {

      return (faces[face] + " of " + suits[suit]);

      }

      CardDeck.h

      # ifndef CARDDECK_H
      # define CARDDECK_H

      # include <iostream>
      # include "Card.h"
      # include <vector>

      class CardDeck {


      public:
      CardDeck();
      void shuffle();

      Card dealCard();
      bool moveCard();

      void printDeck();

      private:
      vector<Card> deck;
      int currentCard;

      };

      #endif

      CardDeck.cpp
      # include <iostream>
      # include <ctime>
      # include <string>
      # include "Player.h"
      # include "Card.h"
      # include "CardDeck.h"

      using namespace std;

      int choice;
      char choices;

      Player player;

      CardDeck deck1;

      Card card1, card2, card3, card4, card5, card6, card7, card8, card9, card10;



      void BlackJackwelcome();
      void BlackJackmenu();
      void BlackJackGame();

      int main() {


      string first;
      string second;


      BlackJackwelcome();
      cout << "nFirst Name: ";
      cin >> first;
      player.setfirstName(first);

      cout << "nSecond Name: ";
      cin >> second;
      player.setsecondName(second);

      cout << "nHi there " + player.getName();
      cout << "n" << endl;

      cout << "Please choose from the menu below what you would like to do " + player.getName() << endl;

      BlackJackmenu();





      }

      void BlackJackwelcome() {

      cout << " ------------------------------------------------------- " << endl;
      cout << " Welcome to BlackJack nnnn " << endl;
      cout << " Please enter your First and Last Name down below " << endl;

      }

      void BlackJackmenu() {
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| 1) Play BlackJack. ||" << endl;
      cout << "|| 2) Rules of the Game. ||" << endl;
      cout << "|| 3) Details of the Designer. ||" << endl;
      cout << "|| 4) Exit the Game. ||" << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cin >> choice;

      if (choice == 1) {
      cout << "Lets play BlackJack" << endl;

      BlackJackGame();

      }
      else if (choice == 2) {
      cout << "You have chosen to know the rules of BlackJack." << endl;
      cout << "Press the 'Enter' Key to continue." << endl;
      cin.get();
      cin.get();
      cout << " The rules of BlackJack are detailed below." << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| Players try to make the highest value hand they can, up to a maximum of 21. ||" << endl;
      cout << "|| Hands valued at 22 or more automatically lose – this is known as going bust. ||" << endl;
      cout << "|| Players can usually stand when they want. In this game the dealer must stand on a soft 17. ||" << endl;
      cout << "|| Hand value is determined by the numerical value of the cards in your hand. ||" << endl;
      cout << "|| Numbered cards are assigned their number in points – 7s are worth 7 points, 3s are worth 3 points, and so on. ||" << endl;
      cout << "||The high cards 10 - K are all worth 10 points, while Aces carry a value of 1 or 11, depending on the value of your hand at any time.||" << endl;
      cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "Lets to go back to the main menu" << endl;
      cout << "Press the 'Enter' key" << endl;
      cin.get();
      BlackJackmenu();

      }
      else if (choice == 3) {
      cout << "You have chosen to read details of the game designer. Press Enter to continue" << endl;
      cin.get();
      cin.get();
      cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "|| Name of the designer is Ryan Fox. ||" << endl;
      cout << "|| Game designed in December 2018. ||" << endl;
      cout << "|| Designed for Coursework assignment COM 357 Object Oriented Programming. ||" << endl;
      cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
      cout << "Lets to go back to the main menu" << endl;
      cout << "Press the 'Enter' key" << endl;
      cin.get();
      BlackJackmenu();
      }
      else if (choice == 4) {
      cout << "Thank you for playing. Good Bye." << endl;
      }
      else if (choice != 4) {


      cout << "Sorry that number is not on the menu. Would you like to see the choices again?" << endl;
      cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
      cin >> choices;

      if (choices == 'Y' || 'y') {
      BlackJackmenu();
      }
      else if (choices == 'N' || 'n') {
      cout << "Thanks for playing. Good Bye." << endl;
      }
      else {
      cout << "Invalid choice. Start the program again please." << endl;

      }

      }


      }

      void BlackJackGame() {

      const int win = 2;
      const int Blackjack = 3;
      const int GAMELIMIT = 21;
      const int Dealer = 17;
      int cardtotal1=0, cardtotal2=0;

      cout << "Let's play BlackJack." << endl;
      cout << "Before we start I am going to show you the deck." << endl;

      deck1.printDeck();

      cout << "After seeing the cards in the deck, whenever you are ready press the 'Enter' key to continue." << endl;
      cin.get();
      cin.get();

      cout << "Firstly, let's shuffle the deck." << endl;
      deck1.shuffle();

      cout << "The cards have been shuffled. Press the 'Enter' to continue to dealing the cards.";
      cin.get();
      cin.get();

      card1 = deck1.dealCard();
      card2 = deck1.dealCard();
      card3 = deck1.dealCard();

      cout << "Players cards are: " << card1.toString() << " and " << card3.toString() << endl;
      cardtotal1;
      cout << "With these cards your total is: " << cardtotal1 << endl;


      cout << "Dealer has " << card2.toString() << " and ****" << endl;






      cout << "Would you like to play again?" << endl;
      cout << "Enter Y/y for YES and enter N/n for NO:" << endl;
      cin >> choices;

      switch (choices) {

      case 'Y':
      case 'y':
      BlackJackGame();
      break;
      case 'N':
      case 'n': cout << "Thanks for playing. Goodbye." << endl;
      break;
      default: cout << "You didn't enter any of the choices needed to proceed. Please enter Y/y for YES or N/n for NO.n";
      }
      return;


      }


      If you can give me any help or advice I would be thankful. I have a feeling it may be the vectors being string values but just want to know I am going in the right direction







      c++





      share







      New contributor




      foxy1000000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      foxy1000000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      foxy1000000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 5 mins ago









      foxy1000000

      1




      1




      New contributor




      foxy1000000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      foxy1000000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      foxy1000000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          foxy1000000 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209762%2fblackjack-game-c%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          foxy1000000 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          foxy1000000 is a new contributor. Be nice, and check out our Code of Conduct.













          foxy1000000 is a new contributor. Be nice, and check out our Code of Conduct.












          foxy1000000 is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209762%2fblackjack-game-c%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Ellipse (mathématiques)

          Quarter-circle Tiles

          Mont Emei