string generate_random_card(string& card_value,string card_suit )
// uses the generate card suit and generate card value functions to make a card and sets the string variable card equal to that. then
// returns the string card.
{
card_suit=(generate_random_suit());
card_value= generate_random_value();
string card= (card_value+card_suit);
cout<<"generating card\n";
return(card);
}
void generate_hand(string& card_value, string& card_suit, string hand[])
//uses random card function and for loop to fill an array called hand
//which is an array of strings holding a suit and value of a card
{
for (int i = 0; i<NUMBER_OF_CARDS_IN_A_HAND; i++)
{
hand[i]=(generate_random_card(card_value,card_suit));
}
}
void check_if_hand_is_legal(string hand[])
{
string card_value;
string card_suit;
int i=1;
while(i<5)
{
if(hand[0]==hand[i])
{
hand[i]==generate_random_card(card_value,card_suit);
cout<<"1 is same as "<<i+1<<endl;
}
i++;
}
i=2;
while(i<5)
{
if(hand[1]==hand[i])
{
hand[i]=generate_random_card(card_value,card_suit);
cout<<"2 is same as "<<i+1<<endl;
}
i++;
}
i=3;
while(i<5)
{
if(hand[2]==hand[i])
{
hand[i]=generate_random_card(card_value,card_suit);
cout<<"3 is same as "<<i+1<<endl;
}
i++;
}
i=4;
while(i<5)
{
if(hand[3]==hand[i])
{
hand[i]=generate_random_card(card_value,card_suit);
cout<<"4 is same as "<<i+1<<endl;
}
i++;
}
}
int main(int argc, char *argv[])
{ int count=0;
string card_value="!";
string card_suit="!";
string card[52];
string hand[NUMBER_OF_CARDS_IN_A_HAND];
generate_hand(card_value,card_suit,hand);
check_if_hand_is_legal(hand);
for(int i=0;i<5;i++)
{
cout<<i+1<<" "<<hand[i]<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
the check if hand is legal function is supposed to check if the card is legal and change it if it isn't. it seems to be checking and recognizing that one is illegal then says its generating a new card but it ends up giving doubles anyway. and another problem it seems to generate the same hand everytime anyway. can anyone help?