Card Repeat

I am creating a card where the player is dealt two cards. I am having trouble with the two cards given to the player because its the same exact cards given to them. For example they are told they have " Nine of Hearts and Nine of Hearts." How do I make sure that cards do not repeat?

I use srand((int) time(0));

and I believe this is the portion of my code where I am having problems.

card one;
card two;


cout<< "What is your name? ";
string name;
getline(cin,name);

double begin_money;
cout<< "How much money would you like to start with? ";
cin>> begin_money;

cout<< name<< ", you have $" << begin_money<< "."<< endl;

cout<< "You got a "<< one.get_rank_string() << " of "<< one.get_suit_string() << " and a "
<< two.get_rank_string()<< " of " << two.get_suit_string()<< "." << endl;
Last edited on
What happens here?
1
2
card one;
card two;


Let me guess, the creation of each card does "Pick a random number from 1-52". That could give you (possible, although not likely) ace of spades 52 times in a row.

That is different from the real world game. There is a deck of unique cards. The deck is shuffled. Then you draw a card from the deck. Every card that you draw is removed from the deck, and therefore cannot be drawn again.

You have two obvious approaches:
1. Shuffle the deck at start and always draw the first card of the remaining deck.
2. Do not shuffle, but draw a random card from the remaining deck.

Either way, you do need a deck that has the cards that have not been drawn yet.
Topic archived. No new replies allowed.