質問編集履歴

2

回答を受けての訂正

2018/04/29 00:58

投稿

mMs7ScOiWNZzOie
mMs7ScOiWNZzOie

スコア14

test CHANGED
File without changes
test CHANGED
@@ -36,159 +36,7 @@
36
36
 
37
37
  ```
38
38
 
39
- Aに3,Bに2を入力するとGame inputが二回表示されてしまいます。while文の閉まり方がおかしいのですか?このプログラム自体に自信がないので詳しく教えてください。
40
39
 
41
- ```
42
-
43
-
44
-
45
- ### 該当のソースコード
46
-
47
-
48
-
49
- `#define _CRT_SECURE_NO_WARNINGS
50
-
51
- #include <stdio.h>
52
-
53
-
54
-
55
-
56
-
57
- int main(void) {
58
-
59
-
60
-
61
- int a;
62
-
63
- int b;
64
-
65
-
66
-
67
- while (1) {
68
-
69
- /*グーチョキパーの手を入れる*/
70
-
71
- printf("Game input: ");
72
-
73
- scanf("%d %d", &a, &b);
74
-
75
-
76
-
77
- if ((a==1 || a==2 || a==3) && (b==1 || b==2 || b==3)) {
78
-
79
- break;
80
-
81
- }
82
-
83
-
84
-
85
-
86
-
87
- /*1,2,3以外は受け付けない*/
88
-
89
- printf("Invalid input (Rock: 1, Scissors: 2, Paper: 3),please try again:");
90
-
91
-
92
-
93
- }
94
-
95
-
96
-
97
-
98
-
99
- switch (a) {
100
-
101
- case 1:
102
-
103
- printf("A: Rock,");
104
-
105
- break;
106
-
107
-
108
-
109
- case 2:
110
-
111
- printf("A: Scissors,");
112
-
113
- break;
114
-
115
-
116
-
117
- case 3:
118
-
119
- printf("A: Paper,");
120
-
121
- break;
122
-
123
- }
124
-
125
- switch (b) {
126
-
127
- case 1:
128
-
129
- printf(" B: Rock;");
130
-
131
- break;
132
-
133
-
134
-
135
- case 2:
136
-
137
- printf(" B: Scissors;");
138
-
139
- break;
140
-
141
-
142
-
143
- case 3:
144
-
145
- printf(" B: Paper;");
146
-
147
- break;
148
-
149
- }
150
-
151
-
152
-
153
- if (a == b) {
154
-
155
- printf("Draw (points: A 0, B 0)\n");
156
-
157
- }
158
-
159
-
160
-
161
- else if (a == 1 && b == 2) {
162
-
163
- printf(" A wins and gets 1 points.\n");
164
-
165
- printf("Winner: A (points: A 1, B 0)\n");
166
-
167
- }
168
-
169
- else if (a == 2 && b == 3) {
170
-
171
- printf(" A wins and gets 2 points.\n");
172
-
173
- printf("Winner: A (points: A 2, B 0)\n");
174
-
175
- }
176
-
177
- else if (a == 3 && b == 1) {
178
-
179
- printf(" A wins and gets 5 points.\n");
180
-
181
- printf("Winner: A (points: A 5, B 0)\n");
182
-
183
- }
184
-
185
-
186
-
187
- else if (a == 1 && b == 2) {
188
-
189
- printf(" B wins and gets 1 points.\n");
190
-
191
- printf("Winner: A (points: A 0, B 1)\n");
192
40
 
193
41
  }
194
42
 
@@ -205,16 +53,6 @@
205
53
  printf(" B wins and gets 5 points.\n");
206
54
 
207
55
  printf("Winner: A (points: A 0, B 5)\n");
208
-
209
- }
210
-
211
-
212
-
213
-
214
-
215
- return(0);
216
-
217
- }
218
56
 
219
57
  ``
220
58
 

1

一回目の質問に対しての回答を受けて変更しました。

2018/04/29 00:58

投稿

mMs7ScOiWNZzOie
mMs7ScOiWNZzOie

スコア14

test CHANGED
File without changes
test CHANGED
@@ -46,150 +46,182 @@
46
46
 
47
47
 
48
48
 
49
+ `#define _CRT_SECURE_NO_WARNINGS
50
+
51
+ #include <stdio.h>
52
+
53
+
54
+
55
+
56
+
57
+ int main(void) {
58
+
59
+
60
+
61
+ int a;
62
+
63
+ int b;
64
+
65
+
66
+
67
+ while (1) {
68
+
69
+ /*グーチョキパーの手を入れる*/
70
+
71
+ printf("Game input: ");
72
+
73
+ scanf("%d %d", &a, &b);
74
+
75
+
76
+
77
+ if ((a==1 || a==2 || a==3) && (b==1 || b==2 || b==3)) {
78
+
79
+ break;
80
+
81
+ }
82
+
83
+
84
+
85
+
86
+
87
+ /*1,2,3以外は受け付けない*/
88
+
89
+ printf("Invalid input (Rock: 1, Scissors: 2, Paper: 3),please try again:");
90
+
91
+
92
+
93
+ }
94
+
95
+
96
+
97
+
98
+
99
+ switch (a) {
100
+
101
+ case 1:
102
+
103
+ printf("A: Rock,");
104
+
105
+ break;
106
+
107
+
108
+
109
+ case 2:
110
+
111
+ printf("A: Scissors,");
112
+
113
+ break;
114
+
115
+
116
+
117
+ case 3:
118
+
119
+ printf("A: Paper,");
120
+
121
+ break;
122
+
123
+ }
124
+
125
+ switch (b) {
126
+
127
+ case 1:
128
+
129
+ printf(" B: Rock;");
130
+
131
+ break;
132
+
133
+
134
+
135
+ case 2:
136
+
137
+ printf(" B: Scissors;");
138
+
139
+ break;
140
+
141
+
142
+
143
+ case 3:
144
+
145
+ printf(" B: Paper;");
146
+
147
+ break;
148
+
149
+ }
150
+
151
+
152
+
153
+ if (a == b) {
154
+
155
+ printf("Draw (points: A 0, B 0)\n");
156
+
157
+ }
158
+
159
+
160
+
161
+ else if (a == 1 && b == 2) {
162
+
163
+ printf(" A wins and gets 1 points.\n");
164
+
165
+ printf("Winner: A (points: A 1, B 0)\n");
166
+
167
+ }
168
+
169
+ else if (a == 2 && b == 3) {
170
+
171
+ printf(" A wins and gets 2 points.\n");
172
+
173
+ printf("Winner: A (points: A 2, B 0)\n");
174
+
175
+ }
176
+
177
+ else if (a == 3 && b == 1) {
178
+
179
+ printf(" A wins and gets 5 points.\n");
180
+
181
+ printf("Winner: A (points: A 5, B 0)\n");
182
+
183
+ }
184
+
185
+
186
+
187
+ else if (a == 1 && b == 2) {
188
+
189
+ printf(" B wins and gets 1 points.\n");
190
+
191
+ printf("Winner: A (points: A 0, B 1)\n");
192
+
193
+ }
194
+
195
+ else if (a == 2 && b == 3) {
196
+
197
+ printf(" B wins and gets 2 points.\n");
198
+
199
+ printf("Winner: A (points: A 0, B 2)\n");
200
+
201
+ }
202
+
203
+ else if (a == 3 && b == 1) {
204
+
205
+ printf(" B wins and gets 5 points.\n");
206
+
207
+ printf("Winner: A (points: A 0, B 5)\n");
208
+
209
+ }
210
+
211
+
212
+
213
+
214
+
215
+ return(0);
216
+
217
+ }
218
+
219
+ ``
220
+
221
+
222
+
49
223
  ```
50
224
 
51
- #define _CRT_SECURE_NO_WARNINGS
52
-
53
- #include <stdio.h>
54
-
55
-
56
-
57
-
58
-
59
- int main(void) {
60
-
61
-
62
-
63
- int a;
64
-
65
- int b;
66
-
67
-
68
-
69
-
70
-
71
- while (1) {
72
-
73
- /*グーチョキパーの手を入れる*/
74
-
75
- printf("Game input: ");
76
-
77
- scanf("%d", &a);
78
-
79
- scanf(" %d", &b);
80
-
81
- /*1,2,3以外は受け付けない*/
82
-
83
- if (a < 1 || a>3 || b < 1 || b>3) {
84
-
85
- printf("Invalid input (Rock: 1, Scissors: 2, Paper: 3),please try again:");
86
-
87
- break;
88
-
89
- }
90
-
91
-
92
-
93
- }
94
-
95
- switch (a) {
96
-
97
- case 1:
98
-
99
- printf("A: Paper,");
100
-
101
- break;
102
-
103
-
104
-
105
- case 2:
106
-
107
- printf("A: Scissors,");
108
-
109
- break;
110
-
111
-
112
-
113
- case 3:
114
-
115
- printf("A: Paper,");
116
-
117
- break;
118
-
119
- }
120
-
121
- switch (b) {
122
-
123
- case 1:
124
-
125
- printf(" B: Paper;");
126
-
127
- break;
128
-
129
-
130
-
131
- case 2:
132
-
133
- printf(" B: Scissors;");
134
-
135
- break;
136
-
137
-
138
-
139
- case 3:
140
-
141
- printf(" B: Paper;");
142
-
143
- break;
144
-
145
- }
146
-
147
-
148
-
149
-
150
-
151
- if (a == b) {
152
-
153
- printf("Draw (points: A)\n");
154
-
155
-
156
-
157
- }
158
-
159
- else if ((a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1)) {
160
-
161
- printf("Winner: A (points:");
162
-
163
-
164
-
165
- }
166
-
167
- else if ((a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1)) {
168
-
169
- printf("Winner: B (points:");
170
-
171
-
172
-
173
- }
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
- return(0);
186
-
187
- }
188
-
189
-
190
-
191
- ```
192
-
193
225
 
194
226
 
195
227
  ### 試したこと