Here's something i whipped up for ya during lunch... it compiles... not sure if it'll help you in your cause...
Code:
#include <time.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
typedef enum Suit
{
HEARTS,
DIAMONDS,
CLUBS,
SPADES,
NUM_SUITS
};
const char* SuitStrings[NUM_SUITS] =
{
"Hearts", "Diamonds", "Clubs", "Spades"
};
typedef enum Value
{
ACE,
DEUCE,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
NUM_VALUES
};
const char* ValueStrings[NUM_VALUES] =
{
"Ace", "Deuce", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen",
"King"
};
typedef struct _Card
{
Value value;
Suit suit;
} Card;
static const int NUM_CARDS = NUM_VALUES * NUM_SUITS;
static const int CARDS_PER_HAND = 5;
int CreateCards(Card* cards)
{
int count = 0;
for(int i = ACE; i < NUM_VALUES; i++)
{
for(int j = HEARTS; j < NUM_SUITS; j++)
{
cards[count].suit = (Suit)j;
cards[count++].value = (Value)i;
}
}
return(1);
}
int SwapCards(Card* card1, Card* card2)
{
Card temp;
temp.suit = card1->suit;
temp.value = card1->value;
card1->suit = card2->suit;
card1->value = card2->value;
card2->suit = temp.suit;
card2->value = temp.value;
return(1);
}
int ShuffleCards(Card* cards)
{
srand(time(NULL));
for(int i = 0; i < NUM_CARDS; i++)
{
SwapCards(&cards[i], &cards[rand() % NUM_CARDS]);
}
return(1);
}
int DealCards(Card* cards, Card* hand[CARDS_PER_HAND])
{
int flags[NUM_CARDS];
memset(flags, 0, sizeof(flags));
for(int i = 0; i < CARDS_PER_HAND; i++)
{
int card = rand() % NUM_CARDS;
if(flags[card])
{
i--;
}
else
{
hand[i] = &cards[card];
flags[card]++;
}
}
return(1);
}
int ShowFacePairs(Card* hand[CARDS_PER_HAND])
{
for(int i = 0; i < CARDS_PER_HAND; i++)
{
for(int j = i + 1; j < CARDS_PER_HAND; j++)
{
if(hand[i]->value == hand[j]->value)
{
cout << "You have a pair of " << ValueStrings[hand[i]->value] << "s\n";
}
}
}
return(1);
}
int ShowCards(Card* hand[CARDS_PER_HAND])
{
for(int i = 0; i < CARDS_PER_HAND; i++)
{
cout << "Card " << i + 1 << " is the ";
cout << ValueStrings[hand[i]->value] << " of ";
cout << SuitStrings[hand[i]->suit] << ".\n";
}
return(1);
}
int main(void)
{
Card cards[NUM_CARDS];
Card *hand[CARDS_PER_HAND];
CreateCards(cards);
ShuffleCards(cards);
DealCards(cards, hand);
ShowCards(hand);
ShowFacePairs(hand);
return(1);
}
good luck
U.