Card Game

i've spent a lot of time making this game; yet it does not give the desired output. I know its a lot to ask, but can someone read the whole code and help?
its a game in which every player is dealt 5 cards each from the deck and then turn by turn each player throws a card and picks a card either from the pile or from the deck to maintain the minimum sum of their 5 cards. in the end the player with the least sum of 5 cards, wins.
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
#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=deck[0];
	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];
	}
	int i=6;
	for(int p2_assign=0; p2_assign<5; p2_assign++){
		player2[p2_assign]=deck[i];
		i++;
	}
	int w=11;
	for(int p3_assign=0; p3_assign<5; p3_assign++){
		player3[p3_assign]=deck[w];
		w++;
	}
	int t=16;
	for(int p4_assign=0; p4_assign<5; p4_assign++){
		player4[p4_assign]=deck[t];
		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;
	}
	for(int i=0; i<5; i++){		
		cout<<player2[i]<<endl;
	}
	for(int i=0; i<5; i++){
		cout<<player3[i]<<endl;
	}
	for(int i=0; i<5; i++){
		cout<<player4[i]<<endl;
	}

	int end_deck=21;
	while (end_deck<=51){
		if (deck[end_deck]<player1[5]){
			current=player1[5];
			player1[5]=deck[end_deck];
			end_deck++;
		}
		else if(current<player1[5]){
			prev=player1[5];
			player1[5]=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[5]){
			current=player2[5];
			player2[5]=deck[end_deck];
			end_deck++;
		}
		else if (current<player2[5]){
			prev=player2[5];
			player2[5]=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[5]){
			current=player3[5];
			player3[5]=deck[end_deck];
			end_deck++;
		}
		else if (current<player3[5]){
			prev=player3[5];
			player3[5]=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[5]){
			current=player4[5];
			player4[5]=deck[end_deck];
			end_deck++;
		}
		else if (current<player4[5]){
			prev=player4[5];
			player4[5]=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";

}
Topic archived. No new replies allowed.