Skip to content

Instantly share code, notes, and snippets.

@ConatserCA
Created October 29, 2014 22:18
Show Gist options
  • Save ConatserCA/c85917f5318f9d39423c to your computer and use it in GitHub Desktop.
Save ConatserCA/c85917f5318f9d39423c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
//variable initialization & labeling the randomizer
static const int nSuit = 4;
static const int nCard = 13;
static const int nHand = 5;
int suit(0), card(0), suitpos(0), cardpos(0), count(1), place(1), buffer(0), initialpos(1);
srand(time(0));
//Setting array values
int placeCard[nCard][nSuit];
string hand1[nHand];
string hand2[nHand];
string deck[nSuit][nCard] = { { "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts" }, { "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades" }, { "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs" }, { "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds" } };
//Shuffle and display
for (suit = 0; suit < nSuit; suit++)
{
for (card = 0; card < nCard; card++)
{
placeCard[card][suit] = count;
count++;
cardpos = (rand() % nCard) + 1;
suitpos = (rand() % nSuit) + 1;
buffer = placeCard[card][suit];
placeCard[card][suit] = placeCard[cardpos][suitpos];
placeCard[cardpos][suitpos] = buffer;
}
}
for (suit = 0; suit < nSuit; suit++)
{
for (card = 0; card < nCard; card++)
{
cout << place << " " << deck[(placeCard[card][suit] - 1)] << endl;
place++;
}
}
cout << endl;
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment