-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcriket.c
319 lines (249 loc) · 7.91 KB
/
criket.c
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
//Harshit khnadelwal
/**/
#include <stdio.h>
int i, j;
struct cric_player
{
char name[30];
int age;
int country;
int category;
int odi;
int int_20;
float batt_score;
int wickets;
};
void country_code();
void num_batsman(struct cric_player cp[], int);
void average_Score(struct cric_player cp[], int);
void num_bowlers(struct cric_player cp[], int);
void max_wickets(struct cric_player cp[], int);
void display_Board(struct cric_player cp[], int);
int main()
{
int choice, n;
printf("\nEnter number of players: ");
scanf("%d", &n);
struct cric_player cp[n];
for (i = 0; i < n; i++)
{
printf("\n************************************************");
printf("\nEnter name of player %d: ", i + 1);
scanf("%s", cp[i].name);
printf("\nEnter age of player: ");
scanf("%d", &cp[i].age);
country_code();
printf("\nEnter country of player: ");
scanf("%d", &cp[i].country);
printf("\n1. Batsman \n2. Bowler \n3. Wicket-keeper \n4. All rounder");
printf("\nEnter category of player: ");
scanf("%d", &cp[i].category);
printf("\nEnter number of ODI's played: ");
scanf("%d", &cp[i].odi);
printf("\nEnter number of International 20-20's played: ");
scanf("%d", &cp[i].int_20);
printf("\nEnter average batting score: ");
scanf("%f", &cp[i].batt_score);
printf("\nEnter total number of wickets taken: ");
scanf("%d", &cp[i].wickets);
}
//displaying the entered information
for (i = 0; i < n; i++)
{
printf("\n\n");
printf("\n************************************************");
printf("\nName of player %d: %s", i + 1, cp[i].name);
printf("\nAge of player: %d", cp[i].age);
printf("\nCountry of player: ");
if (cp[i].country == 1)
printf("India");
else if (cp[i].country == 2)
printf("England");
else if (cp[i].country == 3)
printf("Sri Lanka");
else if (cp[i].country == 4)
printf("Australia");
else
printf("\nPlease check input again.");
printf("\n1. Batsman \n2. Bowler \n3. Wicket-keeper \n4. All rounder");
printf("\nCategory of player: ");
if (cp[i].category == 1)
printf("Batsman");
else if (cp[i].category == 2)
printf("Bowler");
else if (cp[i].category == 3)
printf("Wicket-keeper");
else if (cp[i].category == 4)
printf("All rounder");
else
printf("Please check input again.");
printf("\nNumber of ODI's played: %d", cp[i].odi);
printf("\nNumber of International 20-20's played: %d", cp[i].int_20);
printf("\nAverage batting score: %f", cp[i].batt_score);
printf("\nTotal number of wickets taken: %d", cp[i].wickets);
}
printf("\n\n---*---*---*---*---*---*---*---*---*---*---*---*---*---");
while (1)
{
printf("\n");
printf("\n1. Number of batsman of a particular country.");
printf("\n2. Batsman with highest average score.");
printf("\n3. Number of bowlers of a particular country.");
printf("\n4. Bowler that has taken maximum no of wickets.");
printf("\n5. Show a particular players entire DISPLAY BOARD INFORMATION .");
printf("\n6. Exit.");
printf("\n\nEnter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
num_batsman(cp, n);
break;
case 2:
average_Score(cp, n);
break;
case 3:
num_bowlers(cp, n);
break;
case 4:
max_wickets(cp, n);
break;
case 5:
display_Board(cp, n);
break;
case 6:
return 0;
default:
printf("\nWrong choice . Enter again.");
main();
}
printf("\n\n---*---*---*---*---*---*---*---*---*---*---*---*---*---");
}
return 0;
}
void country_code()
{
printf("\n1. India");
printf("\n2. England");
printf("\n3. Sri Lanka");
printf("\n4. Australia");
}
//1. Number of batsman of a particular country.
void num_batsman(struct cric_player cp[], int num)
{
int coun;
int num_batsman = 0;
country_code();
printf("\nEnter the country code for which number of batsman are to be displayed: ");
scanf("%d", &coun);
for (i = 0; i < num; i++)
{
if (coun == cp[i].country && cp[i].category == 1)
{
num_batsman++;
}
}
printf("\nNumber of batsman are %d.", num_batsman);
}
//2. Batsman with highest average score.
void average_Score(struct cric_player cp[], int num)
{
int max, k;
max = cp[0].batt_score;
for (i = 0; i < num; i++)
{
if (cp[i].category == 1)
{
if (cp[i].batt_score > cp[0].batt_score)
{
max = cp[i].batt_score;
k = i;
}
}
}
printf("\nBatsman with highest average batting score is %s with score %d.", cp[k].name, max);
}
//3. Number of bowlers of a particular country.
void num_bowlers(struct cric_player cp[], int num)
{
int coun;
int num_bowlers = 0;
country_code();
printf("\nEnter the country code for which number of batsman are to be displayed: ");
scanf("%d", &coun);
for (i = 0; i < num; i++)
{
if (coun == cp[i].country && cp[i].category == 2)
{
num_bowlers++;
}
}
printf("\nNumber of bowlers are %d.", num_bowlers);
}
//4. Bowler that has taken maximum no of wickets.
void max_wickets(struct cric_player cp[], int num)
{
int max, k;
max = cp[0].wickets;
for (i = 0; i < num; i++)
{
if (cp[i].category == 2)
{
if (cp[i].wickets > cp[0].wickets)
{
max = cp[i].wickets;
k = i;
}
}
}
printf("\nBowler who has taken maximum number of wickets is %s with score %d.", cp[k].name, max);
}
//5. Show a particular players entire Display board information.
void display_Board(struct cric_player cp[], int num)
{
int player;
printf("\nDISPLAY BOARD INFORMATION");
for (i = 0; i < num; i++)
{
printf("\n%d. ", i + 1);
printf("%s", cp[i].name);
}
printf("\n\nEnter particular player to display his information: ");
scanf("%d", &player);
for (i = 1; i <= num; i++)
{
if (player == i)
{
printf("\n");
printf("\nName of player %d: %s", i, cp[i - 1].name);
printf("\nAge of player: %d", cp[i - 1].age);
printf("\nCountry of player: ");
if (cp[i].country == 1)
printf("India");
else if (cp[i].country == 2)
printf("England");
else if (cp[i].country == 3)
printf("West Indies");
else if (cp[i].country == 4)
printf("Australia");
else
printf("Please check again.");
//printf("\n\n1. Batsman \n2. Bowler \n3. Wicket-keeper \n4. All rounder
printf("\nCategory of player: ");
if (cp[i - 1].category == 1)
printf("Batsman");
else if (cp[i - 1].category == 2)
printf("Bowler");
else if (cp[i - 1].category == 3)
printf("Wicket-keeper");
else if (cp[i - 1].category == 4)
printf("All rounder");
else
printf("Please check input again.");
printf("\nNumber of ODI's played: %d", cp[i - 1].odi);
printf("\nNumber of International 20-20's played: %d", cp[i - 1].int_20);
printf("\nAverage batting score: %f", cp[i - 1].batt_score);
printf("\nTotal number of wickets taken: %d", cp[i - 1].wickets);
}
}
}