Part 1
Create a standard deck of cards using an array. (1-dimensional or 2-dimensional, up to you). The deck should have 52 cards. The deck should have 13 ranks (1 to King) for each of the 4 suits (Spades, Hearts, Clubs and Diamonds).
After that, add in code that will be able to draw a card randomly from the deck.
Part 2
Next implement a 3-card guessing game that will do the following:
1.Draw ONE card each for LEFT, MID and RIGHT.
2.Indicate (or show) the user the cards drawn and their original position.
3.Clearly point out the card in MID.
4.Flip the cards around and shuffle them. (don’t show the player which card is in which position)
5.Let the player guess where the original MID card is.
6.If the player guess correct, declare the player as a winner. If the player guess wrongly, show where the correct card is and declare the player as loser.
7.Ask the player if he/she wish to play again.
What I have tried:
#include<iostream>
#include<cassert>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
const unsigned int DECK_SIZE=52;
const unsigned int MAX_RANK=13;
const unsigned int MAX_SUIT=4;
const string ranks[MAX_RANK]=
{
"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"
};
const string suits[MAX_SUIT]=
{
"Spades","Hearts","Clubs","Diamonds"
};
struct Card
{
string ranks;
string suits;
};
Card deck[DECK_SIZE];
void initializeDeck();
void initializeDeck()
{
int i,j;
int k=0;
for(i=0; i<MAX_RANK; i++)
{
for(j=0; j<MAX_SUIT;j++ )
{
deck[k].ranks=ranks[i];
deck[k].suits=suits[j];
k++;
}
}
}
int main()
{
initializeDeck();
for(int i=0; i<52; i++)
{
int j=(rand()%52);
Card temp=deck[i];
deck[i]=deck[j];
deck[j]=temp;
}
for(int i=0; i<52; i++)
{
cout<<setw(10)<<deck[i].ranks;
cout<<setw(8)<<deck[i].suits;
if (i%4==3)
{
cout<< endl;
}
}
return 0;
}