title: Poker Program in c Programming
body: <p>I've put together a program that deals out a hand poker perfectly. Now I want the program to realize when the hand that is dealt is straight, flush, pair, 3 of a kind, and 4 of kind. The program runs but never prints the right condition when needed to, I believe I have some placement or logic error that I can't find. Here's what I have so far.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  #define SUITS 4
  #define FACES 13
  #define CARDS 52
  #define HAND 5//draw only 5
  #define TRUE 1//positive print condition
  #define FALSE 0//negative print condition
  
  //prototypes
  shuffle( unsigned int wDeck[][FACES]);//shuffling modifies wDeck
  deal(unsigned int wDeck[][FACES], const char *wFace[],
    const char *wSuit[] );//dealing doesn't modify the arrays
  
  
  //true/false conditions
  typedef int bool;
  bool straight, flush, four, three;
  int pairs; //0,1, or 2
  
  
  
  int main()
  {
  //initialize suit array
  const char *suit[ SUITS ] =
      {
          "Hearts", "Diamonds", "Clubs", "Spades"
      };
  
  //initialize face array
  const char *face[ FACES ] =
      {
          "Ace", "Deuce", "Three", "Four",
          "Five", "Six", "Seven", "Eight",
          "Nine", "Ten", "Jack", "Queen", "King"
      };
  
  int suitInHand[SUITS], facesInHand[FACES];
  
  analyzeHand(suitInHand, facesInHand);
  
  //initialize deck array
  unsigned int deck[SUITS][FACES] = { 0 };
  
  srand( time( NULL ) );//seed random-number generator
  
  shuffle( deck );//shuffle the deck
  deal( deck, face, suit );//deal the deck
  
  }//end main
  
  //shuffle cards in deck
  shuffle( unsigned int wDeck[][FACES])
  {
      size_t row;//row number
      size_t column;//column number
      size_t card;//counter
  
      //for each of the cards, choose slot of deck randomly
     for( card = 1; card &lt;= CARDS; ++card) {
  
      //choose new random location until unoccupied slot found
      do {
          row = rand() % SUITS;
          column = rand() % FACES;
      }
      while( wDeck[ row ][ column ] !=0);
      //end do-while
  
      //pace card number in chosen slot of deck
      wDeck[ row ][ column ] = card;
     }//end for
  }//end function shuffle
  
  //deal cards in deck
  deal(unsigned int wDeck[][FACES], const char *wFace[],
       const char *wSuit[] )
  {
      size_t card;//card counter
      size_t row;//row counter
      size_t column;//column counter
  
      //deal each of the cards
      for( card = 1; card &lt;= HAND; ++card) {
  
          //loop through rows of wDeck
          for( row = 0; row &lt; SUITS; ++row) {
  
              //loop through column of wDeck for current row
              for( column = 0; column &lt; FACES; ++column) {
  
                  //if slot contains current card, display card
                  if( wDeck[ row ][ column ] == card ) {
                      printf("%5s of %-8s%c", wFace[ column ], wSuit[ row ],
                             card % 2 == 0 ? '\n' : '\t' );//2 column format
                  }//end if
              }//end for
          }//end for
      }//end for
  }//end function deal
  
  analyzeHand(int suitsInHand[], int facesInHand[])
  {
      int num_consec = 0;
      int rank, suit;
  
      straight = FALSE;
      flush = FALSE;
      four = FALSE;
      three = FALSE;
      pairs = 0;
  
      for (suit = 0; suit &lt; SUITS; suit++)
          if ( suitsInHand[suit] == 5)
                      flush = TRUE;
  
      rank = 0;
      while ( facesInHand[rank] == 0)
          rank++;
  
      for (; rank &lt; FACES &amp;&amp; facesInHand[rank]; rank++)
          num_consec++;
  
      if(num_consec == 5){
          straight = TRUE;
          return;
      }
  
      for(rank = 0; rank &lt; FACES; rank++) {
          if(facesInHand[rank] == 4)
              four = TRUE;
          if(facesInHand[rank] == 3)
              three = TRUE;
          if(facesInHand[rank] == 2)
              pairs++;
      }
  
      if(four)
          printf("Four of a kind\n");
      else if(straight)
          printf("Straight\n");
      else if(pairs == 2)
          printf("Two Pairs\n");
      else if(pairs == 1)
          printf("Pair\n");
      else
          printf("Better Luck Next Time\n");
  }
  </code></pre>