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
|
#include <iostream>
using namespace std;
//declare two string arrays
//one holds the "suit" of the cards, the other hold the "value"
string suit[] = {"Diamonds", "Hearts", "Spades", "Clubs"};
string faceValue[] = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ace", "King", "Queen", "Jack"};
//a function that randomly determines the suit and value of a card
string getCard()
{
string card; //a string that represents a card
//declare two integer variables that create random values
int cardValue = rand() % 12; //creates values between 0 and 11, for randomly determining the face value of a card
int cardSuite = rand() % 4; //creates values between 0 and 3, for determining the suit of a card
card += faceValue[cardValue]; //Add the face value to the string "card"
card += " of "; //a divider in-between the card value and suit
card += suit[cardSuite]; //Add the suit of the card to the string
return card; //output the string
}
int main()
{
//output the randomly picked card to screen
cout << getCard() << endl;
return 0;
}
|