title: I need help generating a deck of cards in C++
body: <p>I am trying to generate a deck of cards using C++. I have already written all of the code, but there is a problem that I can't seem to figure out:</p>
  
  <pre><code>Deck::Deck(){
           Card card;
           bool match = false;
           for (int i=0;i&lt;47;i++){
               do{
                  card.setCard();
                  match = cardInDeck(card, i);
                  }while(match == true);
               match = false;
               cards[i] = card;
           }
           numDrawn = 0;
      }
  </code></pre>
  
  <p>In my constructor for the Deck class, I have a for() loop which generates all 52 cards and makes sure that the deck contains no matching cards. At least it should. The thing is, I can't make the loop iterate more than 47 times and still have it work. Any number over 47 causes the console screen to be empty upon run time, except for the blinking cursor. I am not quite sure what it is about numbers greater than 47 that cause it to stop working. I have tested it extensively and every number between 0 and 48 works.</p>
  
  <p>Maybe I have some tiny error somewhere else in my code that I'm just not seeing. I don't really know. But I would really appreciate any help that I can get. </p>
  
  <p>Here is my full code:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;stdlib.h&gt;
  using namespace std;
  
  void run();
  
  class Card{
        private:
                char suit;
                int value;
        public:
               Card();
               void setCard();
               void getCard();      
               int getValue();
               int getSuit();
        };
  
  class Deck{
        private:
                Card cards[52];
                int numDrawn;
        public:
               Deck();
               void shuffle();
               void draw();
               bool cardInDeck(Card card, int index);
        };
  
  int main(){
      run();
  }
  
  Card::Card(){
       srand(time(NULL));
       value = rand() % 12 + 1;
       suit = rand() % 4 + 1;            
  }
  
  void Card::setCard(){
       value = rand() % 12 + 1;
       suit = rand() % 4 + 1;            
  }
  
  void Card::getCard(){
       cout&lt;&lt;" ----"&lt;&lt;endl&lt;&lt;"|    |"&lt;&lt;endl&lt;&lt;"| ";
  
       if (value == 1) cout&lt;&lt;'A';
       else if (value == 10) cout&lt;&lt;'J';
       else if (value == 11) cout&lt;&lt;'Q';
       else if (value == 12) cout&lt;&lt;'K';
       else cout&lt;&lt;value;
  
       if (suit == 1) cout&lt;&lt;(char)3;
       else if (suit == 2) cout&lt;&lt;(char)4;
       else if (suit == 3) cout&lt;&lt;(char)5;
       else cout&lt;&lt;(char)6;
  
       cout&lt;&lt;" |"&lt;&lt;endl&lt;&lt;"|    |"&lt;&lt;endl&lt;&lt;" ----"&lt;&lt;endl;
  }
  
  int Card::getSuit(){
      return suit;
  }
  
  int Card::getValue(){
      return value;
  }
  
  bool Deck::cardInDeck(Card card, int index){
       bool match;
       for(int i=0;i&lt;=index;i++){
               if((card.getValue() == cards[i].getValue()) &amp;&amp; (card.getSuit() == cards[i].getSuit())){
                    match = true;
                    break;
                    }
               else match = false;
       }
       return match;
  }
  
  Deck::Deck(){
       Card card;
       bool match = false;
       for (int i=0;i&lt;47;i++){
           do{
              card.setCard();
              match = cardInDeck(card, i);
              }while(match == true);
           match = false;
           cards[i] = card;
       }
       numDrawn = 0;
  }
  
  void Deck::shuffle(){
       Card card;
       bool match = false;
       for (int i=0;i&lt;52;i++){
           do{
              card.setCard();
              match = cardInDeck(card, i);
              }while(match == true);
           match = false;
           cards[i] = card;
       }
       numDrawn = 0;        
  }
  
  void Deck::draw(){
       cards[numDrawn].getCard();
       numDrawn++;
  }
  
  void run(){
       Deck cards;
       char choice;
       int cardsDrawn = 0;
       cout&lt;&lt;"Enter 's' to shuffle the deck, 'd' to draw a card, or 'x' to exit:  ";
       do{
       cin&gt;&gt;choice;
       switch(choice){
                      case 'X':
                      case 'x':break;
                      case 'S':
                      case 's':cards.shuffle();
                               cout&lt;&lt;"Deck shuffled."&lt;&lt;endl;
                               cardsDrawn = 0;
                               break;
                      case 'D':
                      case 'd':if (cardsDrawn == 52){
                                   cout&lt;&lt;"Out of cards. Deck reshuffled."&lt;&lt;endl;
                                   cards.shuffle();
                                   cardsDrawn = 0;
                                   break;
                               }
                               else{
                                    cards.draw();
                                    cardsDrawn++;
                                    break;
                               }
                      default: cout&lt;&lt;"Invalid entry.\a Enter a valid option('s','d','x'):  ";
                      }
       }while((choice != 'x') &amp;&amp; (choice != 'X'));
  }
  </code></pre>