-
Notifications
You must be signed in to change notification settings - Fork 0
/
rounds.c
75 lines (70 loc) · 1.15 KB
/
rounds.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
#include <stdio.h>
#include <stdbool.h>
#define rounds 3
char inputYN(char *msg)
{
char input;
bool valid = false;
do
{
printf(msg);
scanf(" %c",&input);
switch (input)
{
case 'Y':
input='Y';
valid=false;
break;
case 'y':
input='Y';
valid=false;
break;
case 'N':
input='N';
valid=false;
break;
case 'n':
input='N';
valid=false;
break;
default :
valid=true;
printf("Please Enter the valid Input");
}
}while(valid);
return input;
}
int main (void)
{
int i,score,totalScore=0,count=1;
float avg=0;
char newPlayer;
while(true)
{
avg = 0;
totalScore = 0;
printf("Enter the score of Player %i (between 0-4)\n",count);
for(i=0;i<3;i++)
{
score = 0;
printf("round %i : ",i+1);
if (scanf("%i",&score)==1 && score<5 && score>=0)
{
totalScore += score;
}
else
{
while (getchar() != '\n');
i--;
printf("Input Valid Score!!\n");
}
}
avg = totalScore/3.0;
printf("Average Score : %.2f",avg);
newPlayer = inputYN("\nDo You want to enter the score of anther player :");
if (newPlayer == 'N')
break;
else
count++;
}
}