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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
#include <cstdlib> //for rand and srand
#include <cstdio>
#include <string>
#include <ctime> // time function for seed value
using namespace std;
#define pause cout << endl; system("pause")
//structure definition
struct card
{
string rank;//this example uses C++ string notation
string suit;
int value;
};
//main function
int main()
{
srand(time(0));
double playon, y, n;
struct card deck[52]; // An array of cards named deck, size 52
const string ranks[ ] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King" };
const string suits[ ] = { "Diamonds", "Hearts", "Spades", "Clubs" };
int k = 0;
for ( int i = 0; i < 13; i++)
{
for ( int j = 0; j < 4; j++)
{
deck[ k ].rank = ranks[ i ];
deck[ k ].suit = suits[ j ];
k++;
}
}
int z = rand () % 52;
cout << deck[ z ].rank << " of " << deck[ z ].suit << endl;
cout << "Would you like another card? " << endl;
cout << "Please enter y or n: " << endl;
cin >> playon;
if (playon == y){
cout << deck[ z ].rank << " of " << deck[ z ].suit << endl;
}
if (playon == n){
cout << "Thank you for playing!" << endl;
}
pause;
return 0;
}
|