Deck of Cards

Can someone help me figure out why this program won't work? It's suppose to simulate a deck of playing cards. 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

Here is my code:
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
#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()
{
	for(int i=0;i<52;i++)
	{
		deck[i]=i;
	}
	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;
} 


Am i writing the dealCard() right? It's suppose to provide the "next" card value from the shuffled deck. If no card remains, then the deck should be reshuffled (reset)
Last edited on
I didn't get any errors when compling using VS2010.

I did get one warning indicating a problem at line 21:
1
2
	unsigned int x;	
	x = 22695477 * x + 1;

You're using x in your calculation, but x is uninitialized.

So if I initialize x everything should be fine? Could you try running it for me to see if it works? I'm not in a computer lab anymore and I don't have the ability to do so on my personal laptop.
Topic archived. No new replies allowed.