C语言考试题大神求代码啊!!!!用随机数生成器列出所有扑克牌的名字

题目有两个要求:1:应用结构体。2:包含两个函数。第一个是洗牌函数shuffer(),第二个dealing()函数(不太明白题意)原文是:Usingarandomnumb... 题目有两个要求:
1:应用结构体。
2:包含两个函数。第一个是洗牌函数shuffer(),第二个dealing()函数(不太明白题意)

原文是:
Using a random number generation to develop a card shuffling and dealing simulation program.1.using shuffer(),and deal() functions to make it work. 2.using structures

牌的数字:
face: 1-13 or{"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}牌的种类:
suit: "hearts", "clubs", "spades", "diamonds"

Output
展开
 我来答
不傻不笨不弱智
2015-12-08 · TA获得超过561个赞
知道小有建树答主
回答量:377
采纳率:100%
帮助的人:316万
展开全部
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
struct cards{
int suit;
int face;
};
char face[13][10]={" Ace","Deuce","Three"," Four"," Five"," Six","Seven","Eight"," Nine"," Ten"," Jack","Queen"," King"};
char suit[4][10]={"hearts ", "clubs ", "spades ", "diamonds"};

void shuffer(struct cards card[])
{
int i, j, a[52], b[52];
srand((int)time(0));
for(i=0; i<52; i++)
a[i] = i;
for(i=0; i<52; i++)
{
j = rand()%52;
if(a[j]!=-1)
{
b[i] = a[j];
a[j] = -1;
}
else
{
while(a[j]==-1)
j=++j%52;
b[i] = a[j];

}

}
for(i=0; i<52; i++)
{
card[i].face = b[i]%13;
card[i].suit = b[i]/13;
}

}
void deal(struct cards card[])
{
int i, j, k;
k = 1;
for(k=0, i=0; i<13; i++)
{
for(j=0; j<4; j++)
{
// printf("%d %d %d\n", k, card[k].suit, card[k++].face);
printf("%s of %s ", face[card[k].face], suit[card[k++].suit]);
}
printf("\n");
}
}
int main()
{
struct cards card[52];
shuffer(card);
deal(card);
}
更多追问追答
追问

大神请问这个error怎么办  我有别的一道题也因为这个卡住了没做出来。。。。

追答
你把文件名改成.cpp试试...
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式