im trying to make a blackjack game using stacks and lists and i am having a problem with my lists, its not being created and i dont know y? the list is a list of cards for the players and the stack is the deck of cards.

#include <stack>
#include <list>
#include <iostream>
#include <conio.h>
#include <ctime>
#include <windows.h>

using namespace std;

const DECKS = 8;
#define H char (3)
#define D char (4)
#define C char (5)
#define S char (6)

/**************************************************************/
struct Card
{
	static int counters[52];
	
	int val; //0-51
	int suit,
		face;
	
	Card();
	~Card() {counters[52]--;};
	Card (const Card& card);
	Card& operator = (Card& card);
	int getSuit() {return suit;};
	int getFace() {return face;};
	void print();
	void printCount() {for(int i = 0; i < 52; i++) cout << counters[i] << endl;}; // delete
};

Card::Card()
{
	val = rand()%52;
	suit = val / 13;
	face = val % 13;
	counters[val]++;
}

Card::Card(const Card& card)
{
	val = card.val;
	suit = card.suit;
	face = card.face;
}
Card& Card::operator = (Card& card)
{
	val = card.val;
	suit = card.suit;
	face = card.face;
	return *this;
}
void Card::print()
{
	switch(face) 
	{
	case 0:

		cout << "Ace";
		break;
	case 10:

		cout << "Jack";
		break;
	case 11:

		cout << "Queen";
		break;
	case 12:

		cout << "King";
		break;
	default:

		cout << face+1;
		break;
	}

	cout << " of ";

	switch(suit)
	{
	case 0:

		cout << H;
		break;
	case 1:

		cout << D;
		break;
	case 2:

		cout << C;
		break;
	case 3:

		cout << S;
		break;
	default:
		break;
	}

}

/**************************************************************/

class Player 
{
private:
	int plyr;	
	int cVal; // sum of all the cards
	list<Card>* hand; // list of cards

public:

	static int players;
	Player();
	~Player() {};
	void recieveCard(Card card);
	int getPlayer() {return plyr;};
	Player& operator= (Player& player);
	bool operator == (Player& player);	
	Player (Player& player);
	int calcHand (int cVal);
	int getHand() {return cVal;};
	void printHand();

};

Player::Player()
{
	cVal = 0;
	plyr = players++;
	hand = new list<Card>;
}


bool Player::operator == (Player& player)
{
	return plyr == player.plyr;
}

void Player::recieveCard(Card card)
{
	hand->push_front(card);
}

Player::Player(Player& player)
{
	plyr = player.plyr;
	cVal = player.cVal;
}

Player& Player::operator= (Player& player)
{
	plyr = player.plyr;
	cVal = player.cVal;
	return *this;
}

int Player::calcHand(int cVal)
{
	return cVal;
}

void Player::printHand()
{
	cout << cVal << endl;
	hand->begin();
	//hand->pop_front();
}

/**************************************************************/

class Playerlist
{
private:
	int size; //number of players
	Player* player; // array of players

public:
	Playerlist();
	~Playerlist();
	Playerlist (const Playerlist& playerlist);
	int getSize() {return size;}

	Player* getPlayer(int index) {return &player[index];}
};

Playerlist::Playerlist()
{
	player = NULL;
	cout << "How many players will be playing? " << endl;
	cout << "There is a limit of 5 players at the blackjack table" << endl;
	cin >> size;
	
	if (size > 5)
	{
		cout << "You cannot have that many player's; 5 max reenter" << endl;
	
	}
	else
	{
	player = new Player [size];
	}
}

Playerlist::~Playerlist()
{
	delete [] player;
}

Playerlist::Playerlist (const Playerlist& playerlist)
{
	size = playerlist.size;
	player = new Player [size];
	for(int s = 0; s < size; s++)
		player[s] = playerlist.player[s];
}

/***************************************************************/

int Player::players = 1; //static # of players
int Card::counters[52] = {0};


void main()
{
	srand(time(NULL));
	Playerlist p;
	list<Card> hand;
    list<Player>::iterator iter;
	stack<Card> deck;
	/*char choice1;
	char choice;*/
	int k = 0;
	int l = 0;
	Card* card;
	Player* player;
	
				player = p.getPlayer(k);
				cout << "Player " << player->getPlayer() << "'s hand" << endl; 
				k = ++k % p.getSize();

			for(int i = 0; i < DECKS; i++)
			{
				card = new Card;
				card->print();
				cout << endl;
				deck.push(*card);
			}
		card->printCount();
		//do
		//{
	while(l < 2)
	{
		for(int d = 0; d < p.getSize(); d++)
		{
			p.getPlayer(d)->recieveCard(deck.top());
			deck.pop();
		}
		l++;
	}
	cout << "Hello" << endl;
		player->printHand();
		/*	for(iter = hand.begin(); iter != hand.end(); ++iter)
			{
			iter->printHand();
			}
			p.getPlayer()->calcHand();
	  if(player->getHand() == 21)
		{
			cout << "You have 21" << endl; 
			return;
		}
	else
	{
			while (player->getHand() < 21)
			{
			cout << "would you like to hit? y or n" << endl;
			cin >> choice1;
			if (choice1 == 'y')
			{
				card = new Card;
				player->recieveCard(*card);
				//hand.push_back(*card);
				player->calcHand();
				if(player->getHand() > 21)
				{
					cout << "Bust" << endl;
					return;
				}
				else if(player->getHand() == 21)
				{
					cout << "You have 21" << endl; 
					return;
				}
				else
				{
					break;
				}				
			}
			else
			return;
		
	} // while
		} // end else*/	
		

	/*} // end if player > size

	}
	//while (choice == 'y'); // end do/while*/
}// end main

where i give the player the card

void Player::recieveCard(Card card)
{
	hand->push_front(card);
}

the print function i am calling

void Player::printHand()
{
	cout << cVal << endl;
	hand->begin();
	//hand->pop_front();
}

ad this is how i implament it

player = p.getPlayer(k);
				cout << "Player " << player->getPlayer() << "'s hand" << endl; 
				k = ++k % p.getSize();

			for(int i = 0; i < DECKS; i++)
			{
				card = new Card;
				card->print();
				cout << endl;
				deck.push(*card);
			}
		card->printCount();
		//do
		//{
	while(l < 2)
	{
		for(int d = 0; d < p.getSize(); d++)
		{
			p.getPlayer(d)->recieveCard(deck.top());
			deck.pop();
		}
		l++;
	}
	cout << "Hello" << endl;
		player->printHand();

where i loop throught the list

for(iter = hand.begin(); iter != hand.end(); ++iter)
			{
				
				iter->printHand();
			}

i get an error saying printHnasd not a member of class Card which i understand but class card does not take care of the players hand thats what Player does

void Player::printHand()
{
   list<Card>::iterator start = hand.begin();  //start "points" to a Card
   list<Card>::iterator stop = hand.end();
   for( ; start != stop; ++start)
  {
      start->print();  //use the print() function of a Card
      cout << endl;
  }
}

that make sence, thx 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.