stuck in while loop

I have been making this card game but in between the code comes a big while loop, and it never ever terminates. Just look at the while loop. PLEASE HELP URGENT.

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
#include <iostream>
using namespace std;

int main(){
	int deck[52]={7,4,13,11,13,6,13,12,11,1,13,5,1,8,3,6,4,12,2,9,8,7,10,7,7,3,1,10,10,6,8,9,12,2,11,5,12,5,3,8,10,9,11,1,4,9,2,3,4,6,2,5};
	int prev=0,current=0;
	if(deck[0]==7 || deck[0]==11)
		 current=0;
	if(deck[0]==12 || deck[0]==13)
		current=10;

	int player1[5];
	int player2[5];
	int player3[5];
	int player4[5];

	for(int p1_assign=0; p1_assign<5; p1_assign++){
		player1[p1_assign]=deck[p1_assign+1];
		if (player1[p1_assign]==7 || player1[p1_assign]==11){
			player1[p1_assign]=0;
		}
		else if (player1[p1_assign]==12 || player1[p1_assign]==13){
			player1[p1_assign]=10;
		}
	}
	int i=6;
	for(int p2_assign=0; p2_assign<5; p2_assign++){
		player2[p2_assign]=deck[i];
		if (player2[p2_assign]==7 || player2[p2_assign]==11){
			player2[p2_assign]=0;
		}
		else if (player2[p2_assign]==12 || player2[p2_assign]==13){
			player2[p2_assign]=10;
		}
		i++;
	}
	int w=11;
	for(int p3_assign=0; p3_assign<5; p3_assign++){
		player3[p3_assign]=deck[w];
		if (player3[p3_assign]==7 || player3[p3_assign]==11){
			player3[p3_assign]=0;
		}
		else if (player3[p3_assign]==12 || player3[p3_assign]==13){
			player3[p3_assign]=10;
		}
		w++;
	}
	int t=16;
	for(int p4_assign=0; p4_assign<5; p4_assign++){
		player4[p4_assign]=deck[t];
		if (player4[p4_assign]==7 || player4[p4_assign]==11){
			player4[p4_assign]=0;
		}
		else if (player4[p4_assign]==12 || player4[p4_assign]==13){
			player4[p4_assign]=10;
		}
		t++;
	}
	int temp=0;


	for(int i=0; i<4; i++){
		for(int j=0; j<4; j++){
			if(player1[j]>player1[j+1]){
				temp=player1[j];
				player1[j]=player1[j+1];
				player1[j+1]=temp;
			}
		}
	}
	for(int i=0; i<4; i++){
		for(int j=0; j<4; j++){
			if(player2[j]>player2[j+1]){
				temp=player2[j];
				player2[j]=player2[j+1];
				player2[j+1]=temp;
			}
		}
	}
	for(int i=0; i<4; i++){
		for(int j=0; j<4; j++){
			if(player3[j]>player3[j+1]){
				temp=player3[j];
				player3[j]=player3[j+1];
				player3[j+1]=temp;
			}
		}
	}
	for(int i=0; i<4; i++){
		for(int j=0; j<4; j++){
			if(player4[j]>player4[j+1]){
				temp=player4[j];
				player4[j]=player4[j+1];
				player4[j+1]=temp;
			}
		} 
	}
	for(int i=0; i<5; i++)
		cout<<player1[i]<<endl;
	cout<<endl;
	for(int i=0; i<5; i++)
		cout<<player2[i]<<endl;
	cout<<endl;
	for(int i=0; i<5; i++)
		cout<<player3[i]<<endl;
	cout<<endl;
	for(int i=0; i<5; i++)
		cout<<player4[i]<<endl;
	cout<<endl;

	int end_deck=21;
	while (end_deck<=51){
		if (deck[end_deck]<=player1[4]){
			current=player1[4];
			player1[4]=deck[end_deck];
			end_deck++;
		}
		else if(current<player1[4]){
			prev=player1[4];
			player1[4]=current;
			current=prev;

		}
		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				if(player1[j]>player1[j+1]){
					temp=player1[j];
					player1[j]=player1[j+1];
					player1[j+1]=temp;
				}
			}
		}

		if (deck[end_deck]<=player2[4] && current>player2[4]){
			current=player2[4];
			player2[4]=deck[end_deck];
			end_deck++;
		}
		else if (current<player2[4]){
			prev=player2[4];
			player2[4]=current;
			current=prev;
		}
		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				if(player2[j]>player2[j+1]){
					temp=player2[j];
					player2[j]=player2[j+1];
					player2[j+1]=temp;
				}
			}
		}
		if (deck[end_deck]<=player3[4] && current>player3[4]){
			current=player3[4];
			player3[4]=deck[end_deck];
			end_deck++;
		}
		else if (current<player3[4]){
			prev=player3[4];
			player3[4]=current;
			current=prev;
		}
		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				if(player3[j]>player3[j+1]){
					temp=player3[j];
					player3[j]=player3[j+1];
					player3[j+1]=temp;
				}
			}
		}
		if (deck[end_deck]<=player4[4] && current>player4[4]){
			current=player4[4];
			player4[4]=deck[end_deck];
			end_deck++;
		}
		else if (current<player4[4]){
			prev=player4[4];
			player4[4]=current;
			current=prev;
		}
		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				if(player4[j]>player4[j+1]){
					temp=player4[j];
					player4[j]=player4[j+1];
					player4[j+1]=temp;
				}
			} 
		}
	}

	int sum1=0,sum2=0,sum3=0,sum4=0, least=1;
	for (int i=0; i<5; i++){
		sum1=sum1+player1[i];
	}
	for (int i=0; i<5; i++){
		sum2=sum2+player1[i];
	}
	for (int i=0; i<5; i++){
		sum3=sum3+player1[i];
	}
	for (int i=0; i<5; i++){
		sum4=sum4+player1[i];
	}

	if(sum1<sum2){
		if(sum1<sum3){
			if(sum1<sum4){
				least=1;
			}
		}
	}
	else if(sum2<sum1){
		if(sum2<sum3){
			if(sum2<sum4){
				least=2;
			}
		}
	}
	else if(sum3<sum1){
		if(sum1<sum2){
			if(sum1<sum4){
				least=3;
			}
		}
	}
	else if(sum4<sum1){
		if(sum1<sum2){
			if(sum1<sum3){
				least=4;
			}
		}
	}
	
	if(least==1)
		cout<<"Player1 wins \n";
	else if(least==2)
		cout<<"Player2 wins \n";
	else if(least==3)
		cout<<"Player3 wins \n";
	else if(least==4)
		cout<<"Player4 wins \n";

}
Instead of starting a new post you should have just added to your first one.

Anyway, add this to the end of your while loop.

cout << end_deck << '\n';

and adding cout<<end_deck; should help me how? I told already that my while loop has become infinite. I need a way to terminate it like it should. The value of end_deck never goes beyond 27
Try using a break statement then
I'd recommend stepping through it in a debugger. That way you'll be able to see exactly how your code is working, which lines it's executing, and what the values of your variables are at each step. That will give you an insight into why it's looping infinitely.
and adding cout<<end_deck; should help me how? I told already that my while loop has become infinite. I need a way to terminate it like it should. The value of end_deck never goes beyond 27


You will never get out of the while loop until the value of end_loop gets to 52. The only time you increment it is the on each of the first ifs. I assume you expect one of the ifs to be true each pass? It looks like that only happened 6 times in how ever long you ran it. If you step through it like MikeyBoy said, you'll be able to see what is happening.
Topic archived. No new replies allowed.