gpt4 book ai didi

Card of Decks 进行特定规模的交易 C 语言

转载 作者:行者123 更新时间:2023-11-30 15:15:23 27 4
gpt4 key购买 nike

大家好,我遇到了一个问题。

我的问题是,我想要一个程序,制作一副普通的牌,洗牌并随机发9手牌(两张牌),然后是3张牌,然后是1张牌,然后是1张牌,然后计算你获得口袋的频率对(两张相同等级的牌),这必须通过工作时的反复试验和跟踪统计来完成。口袋对子来自 9 手牌。

现在为了这个目的,这是我到目前为止所做的1. 创建一副 52 张牌2. 洗牌3.发牌

现在我的代码出现问题,它显示错误。我想要的是处理 9 手牌(两张牌),我只想处理 3 张牌(内部循环的尺寸为 2)(内部循环的尺寸为 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 */

请告诉我问题是什么,如何解决。并分享你的逻辑如何实现主要问题。谢谢

最佳答案

您的交易原型(prototype):

void deal( const Card * const wDeck );

与实现不匹配:

void deal( const Card * const wDeck , int size)

或者你调用它的方式:

deal( deck, 2);

修复原型(prototype),错误就会消失。

关于Card of Decks 进行特定规模的交易 C 语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33656611/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com