Click here to Skip to main content
13,897,313 members
Rate this:
Please Sign up or sign in to vote.
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:


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++ )

int main()
	for(int i=0; i<52; i++)
		int j=(rand()%52);
	 	Card temp=deck[i];

	for(int i=0; i<52; i++)
		if	(i%4==3)
		    cout<<  endl;

	return 0;
Updated 9-Nov-18 23:22pm
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 10-Nov-18 6:53am
Describe the problem in your code.
Po Yang 10-Nov-18 5:29am
Anyone can help me,please.
Rate this: bad
Please Sign up or sign in to vote.

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 10-Nov-18 6:32am
Card deck[3];

void initializeDeck();


int x,y;
int k=0;

for(x=0; x<3; x++)
for(y=0; y<MAX_SUIT;y++ )
Po Yang 10-Nov-18 6:32am
Is it correcct?
OriginalGriff 10-Nov-18 6:42am
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 10-Nov-18 6:48am
It comes out Jack Hearts.I am just a starter only.
OriginalGriff 10-Nov-18 7:11am
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

What is your problem?
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)?
As it stanbds, it is difficult to answer your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190306.1 | Last Updated 10 Nov 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100