Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to fill, shuffle, deal the card game
    text
    copied!<p>I some how got it working but I still have a problem with the sorting and making pairs so that I can determine the winner.</p> <p>Pair them(Pairs are cards with the same value.)e.g Ace of Hearts &amp; Ace of Spades make a pair. I then count those pairs. hand with highest pairs wins.</p> <p>This was what I was trying for the pairing but.. am still rellyy stuck with how I start the comparison to make the pairing.</p> <p>This is the way I expect the results to be for every hand:</p> <p>Hand 1: Six of Spades, is Black Seven of Diamonds, is Red Eight of Spades, is Black Ten of Hearts, is Red Queen of Spades, is Black Number of pairs: 0</p> <p>Hand 2: Three of Spades, is Black Five of Diamonds, is Red Five of Clubs, is Black Nine of Diamonds, is Red Queen of Diamonds, is Red Number of pairs: 1 Highest pair is: Five</p> <pre><code> #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; struct card { const char *face; const char *suit; const char *color; }; typedef struct card Card; typedef unsigned char pairs; void fillDeck( Card * const, const char *[], const char *[] ,const char *[]); void shuffle( Card * const ); void print( const Card * const ); pairs findpairs(card *hand); /* finds any pairs in a hand */ int main() { int hand,cd,winner; card hands[5][5],handssorted[5][5]; pairs numpairs[5],highest; Card deck[52]; const char *face[] = { "Ace", "Two", "Three", "Four", "Five","Six", "Seven", "Eight", "Nine", "Ten","Jack", "Queen", "King"}; const char *suit[] = { "Hearts", "Diamonds", "Clubs", "Spades"}; const char *color[]= {"Black","Red"}; srand( time( NULL ) ); fillDeck( deck, face, suit, color ); print( deck ); printf("\n ---------------------------------------------------------- \n"); shuffle( deck ); print( deck ); for(cd=0;cd&lt;5;cd++) { } for(hand=0;hand&lt;5;hand++) { /* sort the hands here */ numpairs[hand]=findpairs(handssorted[hand]); printf("Hand %i:\n",hand+1); /* print the hands here */ /* print the number and value of any pairs here */ } /* determine the winner and print it */ system("pause"); return 0; } //----------------------------------------------------------------------------- void fillDeck( Card * const wDeck, const char * wFace[], const char * wSuit[], const char * wColor[]) { int i; for ( i = 0; i &lt;= 51; i++ ) { wDeck[i].face = wFace[ i % 13 ]; wDeck[i].suit = wSuit[ i / 13 ]; wDeck[i].color = wColor[i%2]; // if () // wDeck[i].suit = wSuit[ i / 13 ]; } } //------------------------------------------------------------------ void shuffle( Card * const wDeck ) { int i, j; Card temp; for ( i = 0; i &lt;= 51; i++ ) { j = rand() % 52; temp = wDeck[ i ]; wDeck[ i ] = wDeck[ j ]; wDeck[ j ] = temp; } } //--------------------------------- void print( const Card * const wDeck ) { int i; for ( i = 0; i &lt;= 51; i++ ){ printf( "\t%s\t of \t%-8s is \t%s \n \t", wDeck[i].face, wDeck[i].suit,wDeck[i].color, ( i + 1 ) % 2 ? '\t' : '\n' );} } //-------------------------------------------------------------------------- pairs findpairs(card *hand) { pairs numpairs=0; for ( int i = 0; i &lt;= 5; i++ ){ if (hand[i].face == ) } return numpairs; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload