I'm currently making a card dealing program, it is suppose to display a list of cards like this:
"Ace of Heart, is red"
"Two of Heart, is red"
.
.
"Ace of Spade, is black"
and so on for all suits and numbers.
here is my current code:
but the output i get it wrong because it shows:Code:#include <stdio.h> #include <stdlib.h> #include <time.h> struct card { const char *face; const char *suit; const char *color; }; typedef struct card Card; typedef unsigned char pairs; 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"}; void printdeck( const Card * const ); void fillDeck( Card * const, const char *[], const char *[] ,const char *[]); void deal(card cards[52], card hands[5][5]); int main() { int hand,cd,winner; card hands[5][5],handssorted[5][5]; pairs numpairs[5],highest; Card deck[52]; srand( time( NULL) ); fillDeck( deck, face, suit, color ); printdeck(deck); printf("\n ----------------------------------------------------------\n"); system("pause"); return 0; } //------------------------------------------------------------------------------------------------------ void fillDeck( Card * const wDeck, const char * wFace[], const char * wSuit[], const char * wColor[]) { int i; for ( i = 0; i <= 51; i++ ) { wDeck[i].face = wFace[ i % 13 ]; wDeck[i].suit = wSuit[ i / 13 ]; wDeck[i].color = wColor[i%2]; } } //----------------------------------------------------------------------------------------------------- void shuffle( Card * const wDeck ) { int i, j; Card temp; for ( i = 0; i <= 51; i++ ) { j = rand() % 52; temp = wDeck[ i ]; wDeck[ i ] = wDeck[ j ]; wDeck[ j ] = temp; } } //----------------------------------------------------------------------------------------------------------- void printdeck( const Card * const wDeck ) { int i; for ( i = 0; i <= 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' );} }
"Ace of Hearts is Black"
"Two of Hearts is Red"
"Three of Hearts is Black"
.
.
the color displayed is wrong. Im not sure what im doing wrong, can anyone pls help.



LinkBack URL
About LinkBacks


