Click to See Complete Forum and Search --> : blackjack


Hyena
May 7th, 1999, 11:23 AM
my program does not print out the numbers correctly, printing a block instead of the number. this only happens in my if-then-else statement. please help




//program Cards1: blackjack

#include <iostream.h>
#include <time.h>
#include <stdlib.h>
#include <stddef.h>


//---------------------------struct Name-----------------------------
struct Name {
char* suit;
char* type;
};
//-------------------------------------------------------------------



//-------------------------struct oneCard----------------------------
struct oneCard {
int value;
Name name;
};
//-------------------------------------------------------------------





//------------------------class backjack-----------------------------
class blackjack {
public:
initDeck();
//creates a deck of cards

void noRepeat(int&);

void firstDraw();

oneCard card[52];

protected:
int occCard[52];
int pCards[10], cCards[10];
};
//--------------------------------------------------------------------





//-------------------------member functions---------------------------
/********************************************************************/
blackjack::initDeck()
//post: deck is created
{
int cardVal = 2;
int suitNum = 1;


for(int x = 0; x < 52; x++)
{
card[x].name.suit = new char[10];
card[x].name.type = new char[10];
}



for(x = 0; x < 36; x++)
{
card[x].value = cardVal;


switch(suitNum)
{

case 1 :card[x].name.suit = "Hearts";
break;
case 2 :card[x].name.suit = "Spades";
break;
case 3 :card[x].name.suit = "Clubs";
break;
case 4 :card[x].name.suit = "Diamonds";
break;
}


if(suitNum < 4) { suitNum++; }
else {
suitNum = 1;
cardVal++;
}
}



int cardType = 1;
suitNum = 1;


for(x = 36; x < 48; x++)
{
card[x].value = cardVal;



switch(suitNum)
{

case 1 :card[x].name.suit = "Hearts";
break;
case 2 :card[x].name.suit = "Spades";
break;
case 3 :card[x].name.suit = "Clubs";
break;
case 4 :card[x].name.suit = "Diamonds";
break;
}

if(suitNum < 4) { suitNum++; }
else {
suitNum = 1;
}


switch(cardType)
{
case 1:
case 2:
case 3:
case 4 :card[x].name.type = "jack";
break;
case 5:
case 6:
case 7:
case 8 :card[x].name.type = "queen";
break;
case 9:
case 10:
case 11:
case 12 :card[x].name.type = "king";
break;
}

cardType++;
}

suitNum = 1;

for(x = 48; x < 52; x++)
{
card[x].name.type = "ace";
card[x].value = NULL;
switch(suitNum)
{

case 1 :card[x].name.suit = "hearts";
break;
case 2 :card[x].name.suit = "spades";
break;
case 3 :card[x].name.suit = "clubs";
break;
case 4 :card[x].name.suit = "diamonds";
break;
}

if(suitNum < 4) { suitNum++; }
else {
suitNum = 1;
}
}

}
/*******************************************************************/
void blackjack::firstDraw()
//post: player is given cards
{
for(int y = 0; y < 2; y++)
{
pCards[y] = (rand() % 51) + 1;
occCard[y] = pCards[y];
noRepeat(y);
}
}

/*******************************************************************/
void blackjack::noRepeat(int& y)
//pre: an array occCards is given
//post: makes sure every element entered into array is unique
{
for(int x = 0; x < y; x++)
{
if(occCard[y] == occCard[x]) { firstDraw(); }
}
}
/*******************************************************************/









//____________________________-MAIN-_________________________________
void main()
{
randomize();

blackjack b;

b.initDeck();

cout << "You draw: \n";

b.firstDraw();
for(int y = 0; y < 2; y++)
{
if((b.card[y].value != NULL) && (b.card[y].name.type == NULL))
{ cout << b.card[y].value << " of " << b.card[y].name.suit << "\n"; }
else if((b.card[y].value != NULL) && (b.card[y].name.type != NULL))
{ cout << b.card[y].name.type << " of " << b.card[y].name.suit << "\n"; }
else { cout << b.card[y].name.type << " of " << b.card[y].name.suit << "\n"; }
}

}