13,766,769 members
See more:
```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]=
{
};

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;
}```
Posted 9-Nov-18 23:46pm
Updated 10-Nov-18 0:22am
v2
Patrice T 10-Nov-18 5:05am

what is the problem with the code ?
Po Yang 10-Nov-18 5:16am

I need people help me part 2 question
Patrice T 5 days ago

Describe the problem in your code.
Po Yang 10-Nov-18 5:29am

## Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

You've made a start, so test that, and when you are happy it works (and that's not a good shuffle at all but your homework doesn't mention shuffling) move on to the next part of the exercise. Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Po Yang 10-Nov-18 5:37am

I need some begin in part 2
OriginalGriff 10-Nov-18 5:42am

Would you mind explaining that in better detail?

Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Po Yang 5 days ago

Card deck[3];

void initializeDeck();

initializeDeck();

int x,y;
int k=0;

for(x=0; x<3; x++)
{
for(y=0; y<MAX_SUIT;y++ )
{
deck[k].ranks=ranks[x];
deck[k].suits=suits[y];
k++;
}
}
Po Yang 5 days ago

Is it correcct?
OriginalGriff 5 days ago

What happens when you try it?
What testing did you do?

What did the testing show you?

Yes, I could just tell you - but then you'd have to ask about the next bit, and the next, bit, and ... this is not a "remember everything" course - this is a "think about everything" course because it is trying to build a skill set into you - and you only learn skills by using them!
Give it a try - see what you can find out!
Po Yang 5 days ago

It comes out Jack Hearts.I am just a starter only.
OriginalGriff 5 days ago

I kinda guessed that! :laugh:

Stop and think for a minute.
What "comes out Jack Hearts"? When?
All of them?

If it isn't doing exactly what you wanted, then the first thing to do is look at exactly what it is doing, and try to work out where it is going wrong. This is called "debugging" and it's a real skill.

Start by using the debugger, and step your way through the initializeDeck function, watching what happens to each variable as you go. (I can't tell you how to do that as I have no idea what IDE you are using - but Google for the name of your IDE and "debug" and you should find the info you need.)

See what that is doing first, and you should get a clue as to where to go from there.

## Solution 2

Are you able to complete part 1 (show a random card)?
Do you need to actually draw the cards (i.e. do you have to use graphic library)?

Top Experts
Last 24hrsThis month
 OriginalGriff 206 CPallini 205 Richard MacCutchan 150 MadMyche 100 lmoelleb 80
 OriginalGriff 2,427 Richard MacCutchan 1,645 CPallini 744 MadMyche 705 nobita1234 464