大家好我在这里遇到问题。
我的问题是,我想要一个程序,制作一个正常的卡片组,随机播放并随机交易9手牌(两张牌)然后3张牌和1张卡然后另外1张牌,然后计算你多久一次获得一个口袋对(两张相同等级的牌),这必须通过反复试验和跟踪统计来完成。口袋对来自9手。
现在就这个目的来到这里我到现在为止所做的一切 1.创建一副52张牌 2.洗牌 3.交易卡
现在我的代码出现问题,显示错误。我想要的是处理9手牌(两张牌)我只想处理(内圈为2号)3张牌(内圈大小为3)并处理一张(内圈大小为1)但它显示的错误是#"交易过多的论据"。
这是代码
/* Fig. 10.3: cardShuffle.c
The card shuffling and dealing program using structures */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* card structure definition */
struct card {
const char *face; /* define pointer face */
const char *suit; /* define pointer suit */
}; /* end structure card */
typedef struct card Card; /* new type name for struct card */
/* prototypes */
void fillDeck( Card * const wDeck, const char * wFace[],
const char * wSuit[] );
void shuffle( Card * const wDeck );
void deal( const Card * const wDeck );
int main( void )
{
Card deck[ 52 ]; /* define array of Cards */
/* initialize array of pointers */
const char *face[] = { "Ace", "Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King"};
/* initialize array of pointers */
const char *suit[] = { "Hearts", "Diamonds", "Clubs", "Spades"};
srand( time( NULL ) ); /* randomize */
fillDeck( deck, face, suit ); /* load the deck with Cards */
shuffle( deck ); /* put Cards in random order */
deal( deck, 2); /* deal all 52 Cards */
return 0; /* indicates successful termination */
} /* end main */
/* place strings into Card structures */
void fillDeck( Card * const wDeck, const char * wFace[],
const char * wSuit[] )
{
int i; /* counter */
/* loop through wDeck */
for ( i = 0; i <= 51; i++ ) {
wDeck[ i ].face = wFace[ i % 13 ];
wDeck[ i ].suit = wSuit[ i / 13 ];
} /* end for */
} /* end function fillDeck */
/* shuffle cards */
void shuffle( Card * const wDeck )
{
int i; /* counter */
int j; /* variable to hold random value between 0 - 51 */
Card temp; /* define temporary structure for swapping Cards */
/* loop through wDeck randomly swapping Cards */
for ( i = 0; i <= 51; i++ ) {
j = rand() % 52;
temp = wDeck[ i ];
wDeck[ i ] = wDeck[ j ];
wDeck[ j ] = temp;
} /* end for */
} /* end function shuffle */
/* deal cards */
void deal( const Card * const wDeck , int size)
{
int i; /* counter */
/* loop through wDeck */
for ( i = 0; i <= size; i++ ) {
printf( "%5s of %-8s%c", wDeck[ i ].face, wDeck[ i ].suit,( i + 1 ) % 2 ? '\t' : '\n' );
} /* end for */
} /* end function deal */
请告诉我它是如何解决的问题。并分享您的逻辑如何实现主要问题。谢谢
答案 0 :(得分:1)
deal
的原型:
void deal( const Card * const wDeck );
与实施不匹配:
void deal( const Card * const wDeck , int size)
或你打电话的方式:
deal( deck, 2);
修复原型,错误应该消失。