tennis.c
1.35 KB
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
#include <stdio.h>
//This program gets the score of a tennis match and announce it as in
//the commentaries, e.g. 40-30 is forty thirty, and 40-40 is deuce, 15-0 is
// fifteen love.
int main(){
int score1, score2;
printf("Result: ");
scanf("%d-%d", &score1, &score2);
if (score1 == score2){
switch (score1) {
case 0 :
printf("Announcement: love all\n");
break;
case 1 :
printf("Announcement: fifteen all\n");
break;
case 2 :
printf("Announcement: thirty all\n");
break;
case 3 :
printf("Announcement: deuce\n");
break;
}
}
else {
switch (score1) {
case 0 :
printf("Announcement: love ");
break;
case 1 :
printf("Announcement: fifteen ");
break;
case 2 :
printf("Announcement: thirty ");
break;
case 3 :
printf("Announcement: forty ");
break;
}
switch (score2) {
case 0 :
printf("love\n");
break;
case 1 :
printf("fifteen\n");
break;
case 2 :
printf("thirty\n");
break;
case 3 :
printf("forty\n");
break;
}
}
return 0;
}