Help me improve this code

Can Someone suggest how I can improve this code and where I need to improve this?


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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#include<fstream.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<graphics.h>
int query=1;
class manutd
{
public:
char pname[50];
int goals,salary;
}player[17],rplayer[17],r2player[17];

class teams
{public:
char team_name[50];
int skill;
}team[19];

class trnsfr
{
public:
char tname[50];
int tsal;
}tplayer[15];

class general
{
public:
int week;
int mskill;
int tot_goals;
}ob,ob2;

void welcome_screen()
     {
	clrscr();
	textcolor(RED);
	gotoxy(10,10);
	cout<<"**************** W E L C O M E  *********************** ";
	gotoxy(15,12);
	cout<<"*** T O  M A N C H E S T E R   U N I T E D  *** " ;
	gotoxy(10,14);
	textcolor(RED);
	cout<<"******* C L U B  M A N A G E M E N T  ******* ";
	gotoxy(28,16);
	textcolor(RED);
	gotoxy(10,20);
	cout<<"";

	textcolor(RED+BLINK);
	gotoxy(20,30);
	cout<<" *** PRESS ANY KEY TO CONTINUE***";
	getch();
	return;
     }
void initiate()
{
//Player Names
strcpy(r2player[1].pname,"Edwin Van Der Sar");
strcpy(r2player[2].pname,"Patrice Evra");
strcpy(r2player[3].pname,"John O'Shea");
strcpy(r2player[4].pname,"Rio Ferdinand");
strcpy(r2player[5].pname,"Nemanja Vidic");
strcpy(r2player[6].pname,"Darren Fletcher");
strcpy(r2player[7].pname," Michael Carrick");
strcpy(r2player[8].pname," Cristiano Ronaldo");
strcpy(r2player[9].pname," Ryan Giggs");
strcpy(r2player[10].pname," Carlos Tevez");
strcpy(r2player[11].pname," Wayne Rooney");
strcpy(r2player[12].pname," Ben Foster");
strcpy(r2player[13].pname," Rafael De Silva");
strcpy(r2player[14].pname," Ji Sung Park");
strcpy(r2player[15].pname," Dimitar Berbatov");
strcpy(r2player[16].pname," Johny Evans");
strcpy(r2player[17].pname," Paul Scholes");
ob.week=0;
ob.tot_goals=0;
ob2.week=0;
ob2.tot_goals=0;
query++;
//initiations of goals from 0
for(int i=1;i<=17;i++)
{
r2player[i].goals=0;
}

//specify salary given to each player
r2player[1].salary=5000;
r2player[2].salary=3000;
r2player[3].salary=4000;
r2player[4].salary=5000;
r2player[5].salary=4500;
r2player[6].salary=3500;
r2player[7].salary=4000;
r2player[8].salary=7500;
r2player[9].salary=6000;
r2player[10].salary=5000;
r2player[11].salary=6500;
r2player[12].salary=2500;
r2player[13].salary=2500;
r2player[14].salary=3000;
r2player[15].salary=4000;
r2player[16].salary=3000;
r2player[17].salary=5000;
//ob.tot_sal=0;
//for(int j=1;j<=17;j++)
//{
//ob.tot_sal+=player[j].salary;
//}


//Tranfer Players
strcpy(tplayer[1].tname,"Roque Santa Cruz");
tplayer[1].tsal=3000;
strcpy(tplayer[2].tname,"Lionel Messi");
tplayer[2].tsal=6500;
strcpy(tplayer[3].tname,"Amir Zaki");
tplayer[3].tsal=3000;
strcpy(tplayer[4].tname,"Ricardo Kaka");
tplayer[4].tsal=5500;
strcpy(tplayer[5].tname,"Ibrahamovic");
tplayer[5].tsal=4500;
strcpy(tplayer[6].tname,"Luka Modric");
tplayer[6].tsal=4000;
strcpy(tplayer[7].tname,"Peter Crouch");
tplayer[7].tsal=3000;
strcpy(tplayer[8].tname,"Bastian Schweinsteiger");
tplayer[8].tsal=4000;
strcpy(tplayer[9].tname,"Deco");
tplayer[9].tsal=4500;
strcpy(tplayer[10].tname,"Franck Ribery");
tplayer[10].tsal=5000;
strcpy(tplayer[11].tname,"Karim Benzema");
tplayer[11].tsal=2500;
strcpy(tplayer[12].tname,"Mamadou Sakho");
tplayer[12].tsal=2000;
strcpy(tplayer[13].tname,"Wilson Palacios");
tplayer[13].tsal=2500;
strcpy(tplayer[14].tname,"Douglas Costa");
tplayer[14].tsal=2500;
strcpy(tplayer[15].tname,"Nicolas Bertolo");
tplayer[15].tsal=3000;

//EPL Teams:
strcpy(team[1].team_name,"Liverpool");
team[1].skill=18;
strcpy(team[2].team_name,"Chelsea");
team[2].skill=18;
strcpy(team[3].team_name,"Arsenal");
team[3].skill=17;
strcpy(team[4].team_name,"Aston Villa");
team[4].skill=15;
strcpy(team[5].team_name,"Everton");
team[5].skill=14;
strcpy(team[6].team_name,"Fulham");
team[6].skill=13;
strcpy(team[7].team_name,"Tottenham");
team[7].skill=15;
strcpy(team[8].team_name,"West Ham United");
team[8].skill=13;
strcpy(team[9].team_name,"Manchester City");
team[9].skill=15;
strcpy(team[10].team_name,"Wigan Athletic");
team[10].skill=13;
strcpy(team[11].team_name,"Stoke City");
team[11].skill=12;
strcpy(team[12].team_name,"Bolton Wanderers");
team[12].skill=12;
strcpy(team[13].team_name,"Blackburn Rovers");
team[13].skill=13;
strcpy(team[14].team_name,"Portsmouth");
team[14].skill=13;
strcpy(team[15].team_name,"Sunderland");
team[15].skill=12;
strcpy(team[16].team_name,"Newcastle United");
team[16].skill=11;
strcpy(team[17].team_name,"Hull City");
team[17].skill=10;
strcpy(team[18].team_name,"Middlesbrough");
team[18].skill=9;
strcpy(team[19].team_name,"West Bromwich Albion");
team[19].skill=7;

ob.mskill=19;
}

void view_team()
{
clrscr();
ifstream fin("manutd.txt",ios::in);
for(int i=1;i<=17;i++)
{
fin.read((char*)&rplayer[i],sizeof(rplayer[i]));
}
fin.close();

textcolor(RED);
cout<<"\n\tMANCHESTER UNITED";
for(int j=1;j<=17;j++)
{
cout<<"\nPlayer Name: ";
puts(rplayer[j].pname);
cout<<"\nGoals Scored: "<<rplayer[i].goals;
}
cout<<"\n\tTotal Goals scored: "<<ob2.tot_goals;
textcolor(RED+BLINK);
cout<<"PRESS ANY KEY TO RETURN TO MENU";
getch();
}

void save()
{
clrscr();
ofstream fout("manutd.txt",ios::out|ios::app);
fout<<ob2.week;
for(int i=1;i<=17;i++)
{
fout.write((char *)&r2player[i],sizeof(r2player[i]));
}
fout.close();
cout<<" Data Saved!";
gotoxy(10,10);
textcolor(RED+BLINK);
cout<<"PRESS ANY KEY TO RETURN TO MENU";
getch();
}


void simulation()
{
clrscr();
int play[11];
ifstream weekin("manutd.txt",ios::in|ios::beg);
weekin>>ob2.week;
ob2.week++;
for(int i=1;i<=17;i++)
{
weekin.read((char*)&r2player[i],sizeof(r2player[i]));
}
weekin.close();
int n=ob2.week;
cout<<"Week Number: "<<ob2.week;
if(ob2.week>20)
{
n=ob2.week-20;
}
cout<<"\n\t Choose your team using the numbers given:";
for(int j=1;j<=17;j++)
{
cout<<"\n"<<j;
textcolor(RED);
puts(r2player[j].pname);
}
for(int h=1;h<=11;h++)
{
cin>>play[h];
if(play[h]>17 || play[h]<1)
{
cout<<"Wrong choice, Please re-enter";
cin>>play[h];
} }
clrscr();
cout<<"\n\t Your team:";
for(int g=1;g<=11;g++)
{
cout<<"\n";
puts(r2player[play[g]].pname);
cout<<"\n";
}

//scoring
int r=ob.mskill-team[n].skill;
int fg,ag;
	srand(time(NULL));
	if(r==1 || r==2)
	{
	fg=rand()%4;
	ag=rand()%3;
	}
	else if(r==3 || r==4)
	{
	fg=rand()%5;
	ag=rand()%3;
	}
	else if(r>=5 && r<=7)
	{
	fg=rand()%5+1;
	ag=rand()%2;
	}
	else
	{
	fg=rand()%6+1;
	ag=rand()%2;
	}
	ob2.tot_goals+=fg;
//player scores
int s[6];
for(int e=1;e<=fg;e++)
{
s[e]=rand()%11+1;
r2player[play[s[e]]].goals++;
}
cout<<"\n \t At full time, result: ";
cout<<"\n Manchester United "<<fg<<"-"<<ag<<" ";
puts(team[19].team_name);
cout<<"\n Scorer's for Manchester United=\n";
for(int y=1;y<=fg;y++)
{
cout<<"\n";
puts(r2player[play[s[y]]].pname);
}
getch();
return;
}

void transferweek()
{
clrscr();
char c;
int p,s,g;
cout<<"\tWeek 20";
cout<<"\nTRANSFER WEEK";
cout<<"Rules:\n";
cout<<"1)For buying a player, one player has to be sold";
cout<<"\n2)Value ofbought player has to be equal of less than\n sold player\n";
cout<<"\n Do you want to buy?(y/n)";
cin>>c;
switch(c)
{
case 'y':
case 'Y':
s=0;
break;
case 'n':
case 'N':
s=1;
break;
}
while(s=0)
{
cout<<"\nPress number next to desired player\nList of players:\n";
for(int i=1;i<=15;i++)
{
cout<<i;
puts(tplayer[i].tname);
cout<<"---"<<tplayer[i].tsal<<"\n";
}
cin>>p;
clrscr();
cout<<"\n Which player to sell?\n";
for(int q=1;q<=17;q++)
{
cout<<g;
puts(r2player[q].pname);
cout<<"---"<<r2player[q].salary<<"\n";
}
cin>>g;
if(r2player[g].salary>=tplayer[p].tsal)
{
strcpy(r2player[g].pname,tplayer[p].tname);
cout<<"\n \t Negotiations Accomplished. Congratulations!";
}
else
{}
cout<<"\n Another transfer? \n0.Yes 1.No\n";
cin>>s;
}}


void menu()
{
char ch;
clrscr();
       //textbackground(WHITE);
       textcolor(RED);
       gotoxy(30,8);
       cprintf(" N:NEXT WEEK ");
       gotoxy(30,9);
       cprintf(" V:VIEW TEAM INFORMATION \n  \r ");
       gotoxy(30,10);
       cprintf(" S:SAVE DATA \n \r ");
       gotoxy(30,11);
       cprintf(" E:EXIT \n \r ");
       ch=getch();

      switch(ch)
	   {
	     case 'n':
	     case 'N':
		if(ob2.week==19)
		{
		transferweek();
		}
		else{
		simulation();}
		break;
	     case 'v' :
	     case 'V' :
		view_team();
		break;
	     case 's':
	     case 'S':
		save();
		break;
	     case 'e':
	     case 'E':
		system("cls");
		exit(0);
	 }
}

void main()
{
clrscr();
welcome_screen();
initiate();
save();
menu();
getch();
}
Topic archived. No new replies allowed.