Loop issue (I think)

I am brand new to C++ and am trying to make a tic tac toe game. I have run into a problem. Whenever I play the game, the loop starting on line 28 doesn't loop. What is the problem? Also, if there are any other suggestions, please tell me.

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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#include <iostream>
#include <string>

using namespace std;

int main(){

// Initialization

	string box[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
	string player_choice;
	string playagain_yn;
	bool box_XorO[10];				// X is "true", O is "false"
	bool player_turn = true;		// X is "true", O is "false"
	bool player_win = false;
	bool get_winningplayer;			// X is "true", O is "false"
	bool playagain = true;

// Welcome users to game

	cout << "Welcome to Tic-tac-toe by John Doe!\n";
	system("pause");

// Begin game loop

	while(playagain){

		while(!player_win){

// Draw board

			cout << "-------------\n";
			cout << "| " << box[7] << " | " << box[8] << " | " << box[9] << " |\n";
			cout << "|---+---+---|\n";
			cout << "| " << box[4] << " | " << box[5] << " | " << box[6] << " |\n";
			cout << "|---+---+---|\n";
			cout << "| " << box[1] << " | " << box[2] << " | " << box[3] << " |\n";
			cout << "-------------\n";

// Player 1's turn

			if(player_turn){
				cout << "X's turn\n";
				cin >> player_choice;

				if(player_choice == "1"){
					box[1] = "X";
					box_XorO[1] = true;
				}

				if(player_choice == "2"){
					box[2] = "X";
					box_XorO[2] = true;
				}

				if(player_choice == "3"){
					box[3] = "X";
					box_XorO[3] = true;
				}

				if(player_choice == "4"){
					box[4] = "X";
					box_XorO[4] = true;
				}

				if(player_choice == "5"){
					box[5] = "X";
					box_XorO[5] = true;
				}

				if(player_choice == "6"){
					box[6] = "X";
					box_XorO[6] = true;
				}

				if(player_choice == "7"){
					box[7] = "X";
					box_XorO[7] = true;
				}

				if(player_choice == "8"){
					box[8] = "X";
					box_XorO[8] = true;
				}

				if(player_choice == "9"){
					box[9] = "X";
					box_XorO[9] = true;
				}

// Check column win conditions

				if(box_XorO[1] && box_XorO[4] && box_XorO[7]){
					get_winningplayer = true;
					player_win = true;
				}

				else if(box_XorO[2] && box_XorO[5]&& box_XorO[8]){
					get_winningplayer = true;
					player_win = true;
				}

				else if(box_XorO[3] && box_XorO[6] && box_XorO[9]){
					get_winningplayer = true;
					player_win = true;
				}

// Check row win conditions

				else if(box_XorO[1] && box_XorO[2] && box_XorO[3]){
					get_winningplayer = true;
					player_win = true;
				}

				else if(box_XorO[4] && box_XorO[5] && box_XorO[6]){
					get_winningplayer = true;
					player_win = true;
				}

				else if(box_XorO[7] && box_XorO[8] && box_XorO[9]){
					get_winningplayer = true;
					player_win = true;
				}

// Check diagonal win conditions

				else if(box_XorO[1] && box_XorO[5] && box_XorO[9]){
					get_winningplayer = true;
					player_win = true;
				}

				else if(box_XorO[3] && box_XorO[5] && box_XorO[7]){
					get_winningplayer = true;
					player_win = true;
				}

				player_turn = false;

			}

// Redraw board

			cout << "-------------\n";
			cout << "| " << box[7] << " | " << box[8] << " | " << box[9] << " |\n";
			cout << "|---+---+---|\n";
			cout << "| " << box[4] << " | " << box[5] << " | " << box[6] << " |\n";
			cout << "|---+---+---|\n";
			cout << "| " << box[1] << " | " << box[2] << " | " << box[3] << " |\n";
			cout << "-------------\n";

// Player 2's turn

			if(!player_turn){

				cout << "O's turn\n";
				cin >> player_choice;

				if(player_choice == "1"){
					box[1] = "O";
					box_XorO[1] = false;
				}

				if(player_choice == "2"){
					box[2] = "O";
					box_XorO[2] = false;
				}

				if(player_choice == "3"){
					box[3] = "O";
					box_XorO[3] = false;
				}

				if(player_choice == "4"){
					box[4] ="O";
					box_XorO[4] = false;
				}

				if(player_choice == "5"){
					box[5] = "O";
					box_XorO[5] = false;
				}

				if(player_choice == "6"){
					box[6] = "O";
					box_XorO[6] = false;
				}

				if(player_choice == "7"){
					box[7] = "O";
					box_XorO[7] = false;
				}

				if(player_choice == "8"){
					box[8] = "O";
					box_XorO[8] = false;
				}

				if(player_choice == "9"){
					box[9] = "O";
					box_XorO[9] = false;
				}

// Check column win conditions

				if(!box_XorO[1] && !box_XorO[4] && !box_XorO[7]){
					get_winningplayer = false;
					player_win = true;
				}

				else if(!box_XorO[2] && !box_XorO[5]&& !box_XorO[8]){
					get_winningplayer = false;
					player_win = true;
				}

				else if(!box_XorO[3] && !box_XorO[6] && !box_XorO[9]){
					get_winningplayer = false;
					player_win = true;
				}

// Check row win conditions

				else if(!box_XorO[1] && !box_XorO[2] && !box_XorO[3]){
					get_winningplayer = false;
					player_win = true;
				}

				else if(!box_XorO[4] && !box_XorO[5] && !box_XorO[6]){
					get_winningplayer = false;
					player_win = true;
				}

				else if(!box_XorO[7] && !box_XorO[8] && !box_XorO[9]){
					get_winningplayer = false;
					player_win = true;
				}

// Check diagonal win conditions

				else if(!box_XorO[1] && !box_XorO[5] && !box_XorO[9]){
					get_winningplayer = false;
					player_win = true;
				}

				else if(!box_XorO[3] && !box_XorO[5] && !box_XorO[7]){
					get_winningplayer = false;
					player_win = true;
				}

				player_turn = true;

			}

		}

// Declare winner

		if(get_winningplayer){
			cout << "Congratulations X! You have won!\n";
			system("pause");
		}

		else if(!get_winningplayer){
			cout << "Congratulations O! You have won!\n";
			system("pause");
		}

// Do the users wish to play again?

		cout << "Would you like to play another game? y/n\n";
		cin >> playagain_yn;

		while(playagain_yn != "y" && playagain_yn != "n"){
			cout << "Invalid choice. Please try again.\n";
			cin >> playagain_yn;
		}

		if(playagain_yn == "y"){

// Reload game

			box[1] = "1"; box[2] = "2"; box[3] = "3"; box[4] = "4"; box[5] = "5";
			box[6] = "6"; box[7] = "7"; box[8] = "8"; box[9] = "9";
			box_XorO[1] = false; box_XorO[2] = false; box_XorO[2] = false; box_XorO[2] = false; box_XorO[2] = false;
			box_XorO[2] = false; box_XorO[2] = false; box_XorO[2] = false; box_XorO[1] = false;
			player_turn = true;
			player_win = false;
			get_winningplayer = NULL;

		}

		else if(playagain_yn == "n"){

// End game

			playagain = false;
		}

	}

	return 0;

}
whats the problem exactly, the program runs perfectly on my computer. however youre goign to want to redo the win conditions. when i did 7 for X's and 3 for O's it thinks i won. try making an array to store the X's and an array to store the O's
That's the problem. After player 2's turn, it ends the loop.
Topic archived. No new replies allowed.