im trying to write a loop so that 8 of each card in a blackjack game is made and i cant get it to work right. it should print out 8 cards for each card made and delete the card if there are already enough of that type of card and loop through again untill a good card is found but its not doin that any suggestions??
int Card::counters[52] = {0};
for(int i = 0; i < DECKS*52; i++)
{
if(Card::counters[i] < DECKS)
{
// loop untill find good card
card = new Card;
card->print();
cout << endl;
// push only if < max num of each card
if(Card::counters[i] < DECKS)
{
deck.push(*card);
}
else
{
delete card;
}
}
//if not delete card and loop again
}
my card class
struct Card
{
static int counters[52];
int val; //0-51
int suit,
face;
Card();
~Card() {counters[val]--;}
Card (const Card& card);
Card& operator = (Card& card);
int getSuit() {return suit;}
int getFace() {return face;}
int getVal() {return val;}
void print();
void printCount() {for(int i = 0; i < 52; i++) cout << i << ": " << counters[i] << endl;}; // delete
int points();
};
Card::Card()
{
val = rand()%52;
suit = val / 13;
face = val % 13;
points();
counters[val]++;
}
Card::Card(const Card& card)
{
val = card.val;
suit = card.suit;
face = card.face;
points();
}
Card& Card::operator = (Card& card)
{
val = card.val;
suit = card.suit;
face = card.face;
points();
return *this;
}
int Card::points()
{
int num;
if(face == 0)
{
cout << "You have an Ace would you like it to be a 1 or 11?" << endl;
cin >> num;
if(num == 11)
{
return 11;
}
else if(num == 1)
{
return 1;
}
else
{
while (num != 1 || num != 11)
{
cout << "you must enter a 1 or 11" << endl;
return false;
}
}
return false;
}
else if(face >= 10)
{
return 10;
}
else
{
return face+1;
}
}
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;
}
}