teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

編集後のコードを追加

2018/09/28 14:59

投稿

former_neet_cat
former_neet_cat

スコア46

title CHANGED
File without changes
body CHANGED
@@ -172,4 +172,154 @@
172
172
  }
173
173
  }
174
174
 
175
+ ```
176
+
177
+ 上記のコードを直しても正常に動かないので修正後のコードを追記しました。
178
+
179
+ ```lang-c#
180
+ using System;
181
+
182
+ class Overload
183
+ {
184
+
185
+ public void Show()
186
+ {
187
+ var ans = this;
188
+ Console.WriteLine("This ans = {0}", ans);//Ovreload display
189
+ }
190
+
191
+ public int Over(int x, int y)
192
+ {
193
+ int ans = (x + y);
194
+ return ans;
195
+ }
196
+
197
+ public double Over(double x, double y)
198
+ {
199
+ double ans = (x + y);
200
+ return ans;
201
+ }
202
+ }
203
+
204
+ class Start
205
+ {
206
+ public static void Main()
207
+ {
208
+ bool integre = false;
209
+ bool doublegre = false;
210
+ int[] intarray;
211
+ double[] doublearray;
212
+ int x = 0;
213
+ int y = 0;
214
+ double xd = 0;
215
+ double yd = 0;
216
+
217
+ for (int i = 0; i < 2; i++)
218
+ {
219
+ while (true)
220
+ {
221
+ Console.WriteLine("Please enter the digit");
222
+ string num_str = Console.ReadLine();
223
+
224
+ if (!Char.IsDigit(num_str[0]) && num_str[0] != '-')
225
+ {
226
+ Console.WriteLine("Incrrect input");
227
+ Console.WriteLine();
228
+ continue;
229
+ }
230
+ if (integre == false && doublegre == false)
231
+ {
232
+ while (true)
233
+ {
234
+ Console.WriteLine("int or double ?(1 or 2)");
235
+ string select = Console.ReadLine();
236
+
237
+ bool select_roop = false;
238
+
239
+ switch (select)
240
+ {
241
+ case "1":
242
+ Console.WriteLine("You selected 1");
243
+ integre = true;
244
+ select_roop = true;
245
+ break;
246
+
247
+ case "2":
248
+ Console.WriteLine("You selected 2");
249
+ doublegre = true;
250
+ select_roop = true;
251
+ break;
252
+
253
+ default:
254
+ Console.WriteLine("Incrrect input");
255
+ break;
256
+ }
257
+ if (select_roop == true)
258
+ {
259
+ break;
260
+ }
261
+ }
262
+ }
263
+ else if (doublegre == true)
264
+ {
265
+ doublearray = new double[i];
266
+
267
+ if (i == 0)
268
+ {
269
+ xd = double.Parse(num_str);
270
+ doublearray[i] = xd;
271
+ }
272
+ else if (i == 1)
273
+ {
274
+ yd = double.Parse(num_str);
275
+ doublearray[i] = xd;
276
+ }
277
+ else
278
+ {
279
+ Console.WriteLine("Error");
280
+ }
281
+ }
282
+ else
283
+ {
284
+ Console.WriteLine("Error!");
285
+ }
286
+ if (integre == true)
287
+ {
288
+ intarray = new int[2];
289
+
290
+ if (i == 0)
291
+ {
292
+ x = int.Parse(num_str);
293
+ intarray[i] = x;
294
+ }
295
+ else if (i == 1)
296
+ {
297
+ y = int.Parse(num_str);
298
+ intarray[i] = y;
299
+ }
300
+ else
301
+ {
302
+ Console.WriteLine("Error");
303
+ }
304
+ }
305
+ break;
306
+ }
307
+ }
308
+
309
+ if (integre == true)
310
+ {
311
+ Overload ov = new Overload();
312
+ ov.Show();
313
+ Console.WriteLine("ans = {0}",ov.Over(x, y));
314
+ }
315
+
316
+ if (doublegre == true)
317
+ {
318
+ Overload ov = new Overload();
319
+ ov.Show();
320
+ Console.WriteLine("ans = {0}", ov.Over(x, y));
321
+
322
+ }
323
+ }
324
+ }
175
325
  ```