Help making a hat game

Hi. I have a homework assignment that asks me to make a game (The Hat Game).

The game works like this: A hat contains 5 white tokens, 3 blue tokens, and 2 red tokens. The user reaches into the hat and pulls out one random token at a time without replacement. If a white token is picked, the user wins $5. if blue is picked the user wins 410, if the red token is picked the user loses $25. After the user picks a token, the program should ask if the user wants to draw another token from the hat or exit the game. Allow the user to continue playing the game until they decide to not take another token or draw a red token. Each token should add the user's winnings or losses.

I can't figure it out but it never draws a red token for the first one, its always blue or white. Also my total in the main does not add up right.

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
class Hat: public Player
{
public:
	Hat(const char*, int = 0);
	virtual void game();
	virtual void print();
private:
	int draw,plays;
	char playagain[2];
	bool cont;
};
Hat::Hat(const char *n, int p)
	:Player(n)
{
	plays = p;
}
void Hat::game()
{
	float tempwin = 0;
	for(int i = 0; i < plays ;i++)
	{
		cout << endl << "Hat Game " << i+1 << endl;
		int hat[10] = {0,0,0,0,0,1,1,1,2,2};
		cont = true;
		while(cont == true)
		{
			draw = rand()%10;
			while(hat[draw] == -1)
			{
				draw = rand()%10;
			}
			if(hat[draw] == 0)
			{
				cout << "You drew a white token. You win $5." << endl;
				tempwin += 5;
				hat[draw] = -1;
				cout << "Would you like to draw another token? (y/n) ";
				cin >> playagain;
				if(strcmp (playagain, "Y") == 0 || strcmp (playagain, "y") == 0)
					bool cont = true;
				else
				{
					bool cont = false;
					break;
				}
			}
			if(hat[draw] == 1)
			{
				cout << "You drew a blue token. You win $10." << endl;
				tempwin += 10;
				hat[draw] = -1;
				cout << "Would you like to draw another token? (y/n) ";
				cin >> playagain;
				if(strcmp (playagain, "Y") == 0 || strcmp (playagain, "y") == 0)
					bool cont = true;
				else
				{
					bool cont = false;
					break;
				}
			}
			else
			{
				cout << "You drew a red token. You lose $25." << endl;
				tempwin -= 25;
				bool cont = false;
				break;
			}
		} // closes While Loop
		if(tempwin >= 0)
			cout << "You win $" << tempwin << endl;
		else
			cout << "You lose $" << tempwin << endl;
		winnings += tempwin;
	} // closes for loop
}
void Hat::print()
{
	cout << endl;
	cout << "Final results for ";
	Player::print();
	cout << ":" << endl;
	if(winnings >= 0)
		cout << "You won a total of $" << winnings << endl;
	else
		cout << "You lost a total of $" << -1*winnings << endl;
	if(winnings > 0)
	{
		cout << "The casino will add a bonus of " << Player::bonusPercent() * 100 << "% to your winnings." << endl;
		cout << "The casino bonus is $" << Player::bonus() << endl;
		cout << "You came out $" << Player::total() << endl << endl;
	}
	else
		cout << "You get no bonus." << endl;
}


int main()
{
char name[40], hatgame;
	int plays;
	float total;
	total = 0;
	cout << fixed << showpoint << setprecision(2);
	srand((unsigned)time(NULL)); 

	cout << "What is your full name? ";
	cin.getline(name,40);
	Player* ptr;
	
	/*
	// Roulette
	cout << endl << "********* Roulette **********" << endl << endl;
	cout << "How many times would you like to play Roulette? ";
	cin >> plays;
	if(plays > 0)
	{
		ptr = new Roulette(name, plays);
		ptr -> game();
		ptr->print();
		total += ptr->total();
	}
	
	//Chuck-a-Luck
	cout << endl << "********* Chuck - a - Luck **********" << endl << endl;
	cout << "How many times would you like to play Chuck-a-Luck? ";
	cin >> plays;
	if(plays > 0)
	{
		ptr = new Chuck(name, plays);
		ptr -> game();
		ptr -> print();
		total += ptr-> total();
	}

	//Pick 5
	cout << endl << "********* Pick 5 **********" << endl << endl;
	cout << "How many times would you like to play Pick 5? ";
	cin >> plays;
	if(plays > 0)
	{
		ptr = new Pick(name,plays);
		ptr -> game();
		ptr -> print();
		total += ptr -> total();
	}
	*/
	//The Hat Game
	cout << endl << "********* The Hat Game **********" << endl << endl;
	cout << "How many times would you like to play The Hat Game? ";
	cin >> plays;
	if(plays > 0)
	{
			ptr = new Hat(name, plays);
			ptr -> game();
			ptr -> print();
			total += ptr -> total();
	}

	cout << endl << "Your total winnings is $" << total << endl;
	system("PAUSE");

	return 0;
}
Last edited on
What exactly do you mean by "without replacement"?
So there are 5 whites, 3 blues and 2 reds. If I draw a white one I get $5. And then if I want to play again then there will be 4 whites, 3 blues, 2 reds to draw from.
Topic archived. No new replies allowed.