Shuffle and Deal Deck of Cards

Can someone look over my code and see if it looks okay. It won't compile for me and I can't figure out what is wrong. It's suppose to randomly assign numbers to an array to simulate a deck and then shuffle them and then deal (output) 13 hands of 4 cards to make sure the random number generator works.

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include<iostream>
using namespace std;

void display(int arr[], int count);

class DeckOfCards
{
public:
	DeckOfCards();
	void shuffle();
	int dealCard();
private:
	int deck[52];
	int nextCard;
	unsigned int pseudoRand();
};

unsigned int DeckOfCards::pseudoRand()
{
	unsigned int x;	
	x = 22695477 * x + 1;
	x = x%52;
	return x;
}

DeckOfCards::DeckOfCards()
{
        pseudoRand(x);
	for(int i=0;i<52;i++)
	{
		deck[i]=pseudoRand()%52;
	}
	shuffle();
	nextCard=0;
}


void DeckOfCards::shuffle()
{
	int temp, j;
	for(int i=51;i>0;i--)
	{
		j=pseudoRand();
		temp=deck[i];
		deck[i]=deck[j];
		deck[j]=temp;
	}
	return;
}

int DeckOfCards::dealCard()
{
	nextCard++;
	if(nextCard<=52)
	return deck[nextCard-1];
	else
	return -1;
}

int main()
{
	DeckOfCards deck;
	int hand[4];

	for(int i=0;i<13;i++)
	{
		for(int j=0;j<4;j++)
		{
			hand[j]=deck.dealCard();
		}
	display(hand,4);
	}
	return 0;
}

void display(int arr[],int count)
{
	cout<<endl;
	for(int i=0;i<count;i++)
	{
		switch(arr[i]%13)
		{
			case 0:
			cout<<"A ";
			break;
			case 10:
			cout<<"J ";
			break;
			case 11:
			cout<<"Q ";
			break;
			case 12:
			cout<<"K "; 
			break;
			case -1:
			cout<<"[no card] ";
			break;
			default:
			cout<<arr[i]%13<<" ";
		}
	}
	return;
}
It would be easier if you posted the compiler output in full.

return statements are not needed for void functions.
Last edited on
This is the error message I keep getting:

cards.cpp: In function ‘void display(int*, int)’:
cards.cpp:76:15: error: expected initializer before ‘<’ token
cards.cpp:100:1: error: expected primary-expression at end of input
cards.cpp:100:1: error: expected ‘;’ at end of input
cards.cpp:100:1: error: expected primary-expression at end of input
cards.cpp:100:1: error: expected ‘)’ at end of input
cards.cpp:100:1: error: expected statement at end of input
cards.cpp:100:1: error: expected ‘}’ at end of input
This isn't the full output. We don't actually need the full output, but the first few lines of it would be good. The last lines... not so much.
Last edited on
Nevermind I think I figured it out. I missed a part when i was reading the problem. I was suppose to use the class RandomVariable that we used in another problem.
Topic archived. No new replies allowed.