用结构体随机显示54张扑克牌,请问怎样写?

来源:百度知道 编辑:UC知道 时间:2024/05/11 21:36:01
就是随机显示54张牌,用C++结构体,怎样写??

#define HongTao 1
#define FangPian 2
#define HeiTao 3
#define MeiHua 4

struct Poker //扑克牌结构
{
int number; //牌上的数字
int type;
}

Poker p[54];

void main()
{
for (int i = 0 ; i < 54 ; i ++)
{
char sType[2];
p[i].number = 1 + rand() % 15
p[i].type = 1 + rand() % 4

if (p[i].type == 1)
{
strcat(sType , "红桃");
}
if (p[i].type == 2)
{
strcat(sType , "方片");
}
if (p[i].type == 3)
{
strcat(sType , "黑桃");
}
if (p[i].type == 4)
{
strcat(sType , "梅花");
}

if( (p[i].number >= 1) && (p[i].number <= 13) )
{
cout<<sType<<p[i].number<<endl;
}