我是 C++ 新手,我需要模拟一副纸牌并能够从纸牌中随机抽出一张牌。但是我的编码有问题:
#include <iostream>
#include <cstdlib> //for rand and srand
#include <cstdio>
using namespace std;
string suit[] = {"Diamonds", "Hearts", "Spades", "Clubs"};
string facevalue[] = {"Two", "Three", "Four","Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "King", "Ace"};
string getcard()
{string card;
int cardvalue = rand()%12;
int cardsuit = rand()%4;
card += facevalue[cardvalue];
card += "of";
card += suit[cardsuit];
return card;
}
int main ()
{int numberofcards = 0;
for (int = 0; i < numberofcards; i++)
{cout << "You drew a" << getcard() << endl;}
}
当我尝试编译时,它说:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
我不确定我做错了什么。
另外我不知道如何制作我的程序,所以它只画一次而不是无限次。
有什么建议么?