Infinite loop - Blackjack

Heeeello!
So, i've made the game blackjack. When I bet all of my money and get busted the program will reset my player/s. That's a problem, because after the bust the program will ask the user if he/she wants to play again, if 'y' there is no longer a player, but the dealer is still there. The dealer will get cards but as there are no players the dealer will go into an infinite loop.

I can't see what I should do, please help. And if you want to see inside a function, please say so.

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

int Game::init()
{
	mRun = true;
	return 0;
}

bool Game::checkBets(Player& player)
{
	if (player.getBet() > 0)
		return true;

	return false;
}


int Game::run()
{
	init();

	while (mRun)
	{
		int choice = 0;
		cout << "BLACKJACK!\n\n" << "1) Play Game\n2) Exit\n";
		(cin >> choice).get();

		switch (choice)
		{
		case 1:
			{
				int players = 0;
				cout << "Select players (1-5) : ";
				(cin >> players).get();
			
				if (players < 1 || players > 5)
				{
					cout << "error, " << players << " is not a valid input\n";
				}
				else
				{
					game(players);
				}
				break;
			}
		case 2:
			mRun = false;
			break;
		default:
			cout << "Incorrect input\n";
			break;
		}
	}

	return 0;
}



void Game::game(int players)
{

	PlayerList playerList;

	for (unsigned int i = 0; i < players; i++)
	{
		std::string tmpName;
		cout << "Player " << i + 1 << " , please enter your name: ";
		getline(cin, tmpName);
		Player tmpPlayer(tmpName);
		playerList.addPlayer(tmpPlayer);
	}

	bool play = true;
	while (play)
	{
		playerList.makeBet();

		//PlayerList inGameList = playerList.createNewPlayerList();		// a list of players that made a bet (non betting players are exluded from this round)
		Dealer dealer;
		bool firstRound = true;
		if (!playerList.empty())	
		{
			srand(time(0));
			while (true)
			{
				playerList.checkMoney();	// removes a player if he has 0 money
				if (firstRound)	// if it is the first round, draw two cards;
				{
					dealer.drawCard();
					dealer.drawCard();
					playerList.drawCard();
					playerList.drawCard();
				
					firstRound = false;
				}
				else
				{
					playerList.drawCard();
					dealer.drawCard();
				}
				dealer.printHand();
				playerList.printHand();
				dealer.checkBusted();			// check if the dealer is busted
				playerList.checkForBusted(dealer);	// check if any players are busted
				playerList.makeChoice(dealer);
				dealer.makeChoice(&playerList);			// dealer makes his choice 
				
				if (playerList.playerStatusBust())
				{
					playerList.playersLose();
					cout << "\nAll players BUST\n";
					if (playerList.continueGame())
					{
						playerList.resetPlayers();
						dealer.reset();
						
						firstRound = true;
						break;
					}
					else if (!playerList.continueGame())
					{
						play = false;
						break;
					}
				}
				
				if (playerList.playerStatus(dealer))								// if so proceed to the verdict of the game
				{
					dealer.printFullHand();
					playerList.verdict(dealer);
					if (playerList.continueGame())
					{
						
						playerList.resetPlayers();
						dealer.reset();
						
						firstRound = true;
						break;
					}
					else
					{
						play = false;
						break;
					}
				}

			}
		}
		else
		{
			cout << "No bets have been made, please make a bet.\n";
		}

	}
}
Okey, need to add more information. When the player have no money left, he will be resetted. Not just when busted.
You can play till all the money is gone, then there is an infinite loop.
bump
Topic archived. No new replies allowed.