回答編集履歴
1
ソース追記
test
CHANGED
@@ -1,103 +1,167 @@
|
|
1
|
-
|
1
|
+
BAが出たようなので・・・
|
2
2
|
|
3
|
-
```
|
3
|
+
```c
|
4
4
|
|
5
|
-
|
5
|
+
#include <stdio.h>
|
6
6
|
|
7
|
-
|
7
|
+
#include <stdlib.h>
|
8
8
|
|
9
|
+
//
|
10
|
+
|
9
|
-
|
11
|
+
//0〜9の乱数を発生させる。
|
12
|
+
|
13
|
+
int rand_n(void);
|
14
|
+
|
15
|
+
//入力された数字とコンピュータが出した数字を比較して点数を返す。
|
16
|
+
|
17
|
+
int guess(int);
|
18
|
+
|
19
|
+
//
|
20
|
+
|
21
|
+
/*************************************
|
22
|
+
|
23
|
+
*************************************/
|
24
|
+
|
25
|
+
//
|
26
|
+
|
27
|
+
int rand_n(void) { return rand() % 10; }
|
28
|
+
|
29
|
+
//
|
30
|
+
|
31
|
+
int guess(int f)
|
32
|
+
|
33
|
+
{
|
34
|
+
|
35
|
+
static int cnt = 1;
|
36
|
+
|
37
|
+
static const int point[] = {
|
38
|
+
|
39
|
+
// 10回ぐらいでプレイヤーが勝つ
|
40
|
+
|
41
|
+
// 400, 300, 250, 150, 100, 50, -10, -20, -30, -50
|
42
|
+
|
43
|
+
// 30回ぐらいでプレイヤーが勝つ
|
44
|
+
|
45
|
+
200, 100, 50, 25, 10, 0, -25, -50, -100, -200
|
10
46
|
|
11
47
|
|
12
48
|
|
13
|
-
|
49
|
+
};
|
14
50
|
|
15
|
-
|
51
|
+
int g;
|
16
52
|
|
17
|
-
|
53
|
+
char buf[32];
|
18
54
|
|
19
|
-
Selected number is 1
|
20
55
|
|
21
|
-
2
|
22
56
|
|
23
|
-
|
57
|
+
printf("Stage%d: Yor point is %d\n", cnt, f);
|
24
58
|
|
25
|
-
数字を予測してください。
|
59
|
+
puts("数字を予測してください。");
|
26
60
|
|
27
|
-
|
61
|
+
//
|
28
62
|
|
29
|
-
|
63
|
+
fgets(buf, sizeof buf, stdin);
|
30
64
|
|
31
|
-
|
65
|
+
sscanf(buf, "%d", &g);
|
32
66
|
|
33
|
-
|
67
|
+
// 緊急脱出用^^;
|
34
68
|
|
35
|
-
|
69
|
+
if (0 > g || g > 9) {
|
36
70
|
|
37
|
-
|
71
|
+
puts("quit!");
|
38
72
|
|
39
|
-
|
73
|
+
exit(1);
|
40
74
|
|
41
|
-
|
75
|
+
}
|
42
76
|
|
43
|
-
|
77
|
+
//
|
44
78
|
|
45
|
-
|
79
|
+
printf("Selected number is %d\n\n", g);
|
46
80
|
|
47
|
-
|
81
|
+
//
|
48
82
|
|
49
|
-
|
83
|
+
int p = abs(rand_n() - g); // abs()は結果が負になった時の対策
|
50
84
|
|
51
|
-
|
85
|
+
// for DEBUG
|
52
86
|
|
53
|
-
|
87
|
+
if (p == 0) {
|
54
88
|
|
55
|
-
|
89
|
+
puts("equal");
|
56
90
|
|
57
|
-
|
91
|
+
}
|
58
92
|
|
59
|
-
|
93
|
+
// printf("%d\n", p);
|
60
94
|
|
61
|
-
|
95
|
+
//
|
62
96
|
|
63
|
-
|
97
|
+
f += point[p];
|
64
98
|
|
65
|
-
|
99
|
+
//
|
66
100
|
|
67
|
-
|
101
|
+
cnt++;
|
68
102
|
|
69
|
-
|
103
|
+
//
|
70
104
|
|
71
|
-
|
105
|
+
return f;
|
72
106
|
|
73
|
-
|
107
|
+
}
|
74
108
|
|
75
|
-
数字を予測してください。
|
76
109
|
|
77
|
-
1
|
78
110
|
|
79
|
-
|
111
|
+
int main(void)
|
80
112
|
|
81
|
-
|
113
|
+
{
|
82
114
|
|
83
|
-
|
115
|
+
puts("guess NUMBER");
|
84
116
|
|
85
|
-
数字を予測してください。
|
86
117
|
|
87
|
-
1
|
88
118
|
|
89
|
-
|
119
|
+
puts("0~9の数字がランダムに選択されるので、\n"
|
90
120
|
|
91
|
-
|
121
|
+
"選択された数字を当ててください。\n");
|
92
122
|
|
93
|
-
8st stage: Yor point is 1140
|
94
123
|
|
95
|
-
Your wins v^^
|
96
124
|
|
125
|
+
puts("You have 50 points\n");
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
int f = 50;
|
130
|
+
|
131
|
+
do{
|
132
|
+
|
133
|
+
f = guess(f);
|
134
|
+
|
135
|
+
}while (f > 0 && f < 1000);
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
//
|
140
|
+
|
141
|
+
if (f <= 0) {
|
142
|
+
|
143
|
+
puts("your loss ;-p");
|
144
|
+
|
145
|
+
} else {
|
146
|
+
|
147
|
+
puts("Your wins v^^");
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
//
|
152
|
+
|
97
|
-
Quit this game!
|
153
|
+
puts("Quit this game!");
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
return 0;
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
98
162
|
|
99
163
|
```
|
100
164
|
|
101
|
-
|
165
|
+
一応動作確認はしていますが、分かるでしょうか?
|
102
166
|
|
103
|
-
|
167
|
+
何かいい変数名がないかちょっと考えたのですが、このままとします。
|