//BlackJack
// Plays a simple version of the casino style game of blackjack; 1 - 7 players
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>

using namespace std;
class Card
{
public:
    enum rank {ACE = 1, TWO , THREE , FOUR , FIVE , SIX , SEVEN , EIGHT , NINE , TEN , JACK , QUEEN , KING};
    enum suit {CLUBS , DIAMONDS , HEARTS , SPADES};

    //overloading <<operator so can send the Card object to standart output friend ostream& os, const Card& aCard);

    Card(rank r= ACE, suit s = SPADES , bool ifu = true);

    //returns the value of a card , 1 - 11
    int GetValue() const;

    //flips a card; if face up, becomdes face down and vice versa
    void Flip();

private:
    rank m_Rank;
    suit m_Suit;
    bool m_IsFaceup;
};

Card::Card(rank r, suit s, bool ifu): m_Rank(r) , m_Suit(s) , m_IsFaceup(ifu)
{}

int Card::GetValue() const
{
    //if a cards is face down, its value is 0
    int value = 0;
    if (m_IsFaceup)
    {
        //value is number showing on card
        value = m_Rank;
        //value is 10 for face cards
        if (value > 10)
        {
            value = 10;
        }
    }
    return value;
}
void Card::Flip()
{
    m_IsFaceup = ! (m_IsFaceup);
}
class Hand
{
public:
    Hand();

    virtual ~Hand();

    //adds a card to the hand
    void Add(Card*pCard);

    //clears hand of all cards
    void Clear();

    //gets hand total value, intelligently treats aces as 1 or 11
    int GetTotal() const;

protected:
    vector<Card*> m_Cards;
};

Hand::Hand()
{
    m_Cards.reserve(7);
}

Hand::~Hand()
{
    Clear();
}

void Hand::Add(Card*pCard)
{
    m_Cards.push_back(pCard);
}

void Hand::Clear()
{
    //iterate through vector , freeing all memory on the heap vector<Card*>::iterator iter = m_Cards.being(); for (iter = m_Cards.begin(); iter !=m_Cards.end(); ++iter)
    {
        delete *iter;
        *iter = 0;
    }
    //clear vector of pointers
    m_Cards.clear();
}

int Hand::GetTotal() const
{
    //if no cards in hand, return 0
    if (m_Cards.empty())
    {
        return 0;
    }

}

//if a first card has a value of 0, then card is face down; return 0
if (m_cards[0]->GetValue() == 0)
{
    return 0;
}

//add up card values , treast each ace as 1
int total = 0;
vector<Card*>::const_iterator iter;
for (iter = m_Cards.begin(); iter!=m_Cards.end(); ++iter)
{
    if ((*iter)->GetValue() == Card::ACE)
    {
        containsAce = true;
    }

}

*Where i First reference *iter, it says im using a undeclarified Identifior. I understand what this error means, but dont see why im getting the error, is someone could help me i'd appreciate it. Thanks!

Recommended Answers

All 3 Replies

Where the *occur next to the text are where my errors are. Lines 94-95.

That is because you have the declaration commented out on line 92.

void Hand::Clear()
{
    //iterate through vector , freeing all memory on the heap vector<Card*>::iterator iter = m_Cards.being(); for (iter = m_Cards.begin(); iter !=m_Cards.end(); ++iter)
    {
        delete *iter;
        *iter = 0;
    }
    //clear vector of pointers
    m_Cards.clear();
}

Should be

void Hand::Clear()
{
    //iterate through vector , freeing all memory on the heap 
    vector<Card*>::iterator iter = m_Cards.being(); 
    for (iter = m_Cards.begin(); iter !=m_Cards.end(); ++iter)
    {
        delete *iter;
        *iter = 0;
    }
    //clear vector of pointers
    m_Cards.clear();
}

AH! I see. Thanks you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.