1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cstring> // <--
using namespace std;
void shuffleAndDeal(int[][13], const char*[], const char *[]);
int main()
{
const char *suit[4] = { "Hearts", "Diamonds", "Clubs", "Spades" };
const char *face[13] = { "Ace", "Deuce", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
int deck[4][13] = { 0 };
srand(time(0));
shuffleAndDeal(deck, face, suit);
system("pause");
}
void shuffleAndDeal(int deck[][13], const char*face[], const char *suit[])
{
int facerand, suitrand;
char temp[50]; // <--
for (int i = 1; i <= 26; i++)
{
facerand = rand() % 13;
suitrand = rand() % 4;
strcpy(temp,face[facerand]); // <-- etc
strcat(temp, " of ");
strcat(temp, suit[suitrand]);
cout << left << setw(20) << temp;
facerand = rand() % 13;
suitrand = rand() % 4;
cout << face[facerand] << " of " << suit[suitrand] << endl;
}
}
|