質問編集履歴

1

コードをインデント

2020/03/12 08:09

投稿

Gunjirk
Gunjirk

スコア23

test CHANGED
File without changes
test CHANGED
@@ -40,270 +40,274 @@
40
40
 
41
41
 
42
42
 
43
- using System;
44
-
45
- using System.Collections.Generic;
46
-
47
- using System.ComponentModel;
48
-
49
- using System.Data;
50
-
51
- using System.Drawing;
52
-
53
- using System.Linq;
54
-
55
- using System.Text;
56
-
57
- using System.Threading.Tasks;
58
-
59
- using System.Windows.Forms;
60
-
61
-
62
-
63
- namespace WindowsFormsApp1
64
-
65
- {
66
-
67
- public partial class Form1 : Form
68
-
69
- {
70
-
71
-
72
-
73
- public Form1()
74
-
75
- {
76
-
77
- InitializeComponent();
78
-
79
- }
80
-
81
-
82
-
83
- bool isFirst = true;
84
-
85
- double val1 = 0;
86
-
87
-
88
-
89
- private void Form1_Load(object sender, EventArgs e)
90
-
91
- {
92
-
93
-
94
-
95
- }
96
-
97
-
98
-
99
- private void btnNumber_Click(object sender, EventArgs e)
100
-
101
- {
102
-
103
- if (isFirst)
104
-
105
- {
106
-
107
- txtDisplay.Text = "";
108
-
109
- isFirst = false;
110
-
111
- }
112
-
113
- String text = txtDisplay.Text + ((Button)sender).Text;
114
-
115
-
116
-
117
- //文字列 -> 数値
118
-
119
- double d = Convert.ToDouble(text);
120
-
121
-
122
-
123
- //数値 -> 文字列(先頭の0が消える)
124
-
125
- String text2 = d.ToString();
126
-
127
- txtDisplay.Text = text2;
128
-
129
- }
130
-
131
-
132
-
133
- enum sign { blank, ADD, SUB, MUL, DIV };
134
-
135
- sign exec = sign.blank;
136
-
137
-
138
-
139
- //クリア
140
-
141
- private void button_clear_Click(object sender, EventArgs e)
142
-
143
- {
144
-
145
- exec = sign.blank;
146
-
147
- txtDisplay.Text = "0";
148
-
149
- val1 = 0;
150
-
151
- isFirst = true;
152
-
153
- }
154
-
155
-
156
-
157
- //小数点
158
-
159
- private void button_dot_Click(object sender, EventArgs e)
160
-
161
- {
162
-
163
- //小数点の重複チェック
164
-
165
- if(txtDisplay.Text.IndexOf(".") >= 1)
166
-
167
- {
168
-
169
- //すでに小数点がある
170
-
171
- return;
172
-
173
- }
174
-
175
- txtDisplay.Text = txtDisplay.Text + ".";
176
-
177
-
178
-
179
- }
180
-
181
-
182
-
183
- //足し算。
184
-
185
- private void button_tasu_Click(object sender, EventArgs e)
186
-
187
- {
188
-
189
- if (!isFirst) calc();
190
-
191
- exec = sign.ADD;
192
-
193
- }
194
-
195
-
196
-
197
- //引き算。
198
-
199
- private void button_hiku_Click(object sender, EventArgs e)
200
-
201
- {
202
-
203
- if (!isFirst) calc();
204
-
205
- exec = sign.SUB;
206
-
207
- }
208
-
209
-
210
-
211
- //掛け算。
212
-
213
- private void button_kakuru_Click(object sender, EventArgs e)
214
-
215
- {
216
-
217
- if (!isFirst) calc();
218
-
219
- exec = sign.MUL;
220
-
221
- }
222
-
223
-
224
-
225
- //割り算。
226
-
227
- private void button_waru_Click(object sender, EventArgs e)
228
-
229
- {
230
-
231
- if (!isFirst) calc();
232
-
233
- exec = sign.DIV;
234
-
235
- }
236
-
237
-
238
-
239
- //イコール。
240
-
241
- private void button_wa_Click(object sender, EventArgs e)
242
-
243
- {
244
-
245
- calc();
246
-
247
- }
248
-
249
-
250
-
251
- private void calc()
252
-
253
- {
254
-
255
- double val2 = Convert.ToDouble(txtDisplay.Text);
256
-
257
- switch (exec)
258
-
259
- {
260
-
261
- case sign.ADD:
262
-
263
- val1 += val2;
264
-
265
- break;
266
-
267
- case sign.SUB:
268
-
269
- val1 -= val2;
270
-
271
- break;
272
-
273
- case sign.MUL:
274
-
275
- val1 *= val2;
276
-
277
- break;
278
-
279
- case sign.DIV:
280
-
281
- val1 /= val2;
282
-
283
- break;
284
-
285
- default:
286
-
287
- val1 = val2;
288
-
289
- break;
290
-
291
- }
292
-
293
-
294
-
295
- double result = Math.Truncate(val1 * 100.0) / 100.0;
296
-
297
-
298
-
299
- txtDisplay.Text = result.ToString();
300
-
301
- isFirst = true;
302
-
303
- }
304
-
305
- }
306
-
307
-
308
-
309
- }
43
+
44
+
45
+ > using System;
46
+
47
+ > using System.Collections.Generic;
48
+
49
+ > using System.ComponentModel;
50
+
51
+ > using System.Data;
52
+
53
+ > using System.Drawing;
54
+
55
+ > using System.Linq;
56
+
57
+ > using System.Text;
58
+
59
+ > using System.Threading.Tasks;
60
+
61
+ > using System.Windows.Forms;
62
+
63
+ >
64
+
65
+ > namespace WindowsFormsApp1
66
+
67
+ > {
68
+
69
+ > public partial class Form1 : Form
70
+
71
+ > {
72
+
73
+ >
74
+
75
+ > public Form1()
76
+
77
+ > {
78
+
79
+ > InitializeComponent();
80
+
81
+ > }
82
+
83
+ >
84
+
85
+ > bool isFirst = true;
86
+
87
+ > double val1 = 0;
88
+
89
+ >
90
+
91
+ > private void Form1_Load(object sender, EventArgs e)
92
+
93
+ > {
94
+
95
+ >
96
+
97
+ > }
98
+
99
+ >
100
+
101
+ > private void btnNumber_Click(object sender, EventArgs e)
102
+
103
+ > {
104
+
105
+ > if (isFirst)
106
+
107
+ > {
108
+
109
+ > txtDisplay.Text = "";
110
+
111
+ > isFirst = false;
112
+
113
+ > }
114
+
115
+ > String text = txtDisplay.Text + ((Button)sender).Text;
116
+
117
+ >
118
+
119
+ > //文字列 -> 数値
120
+
121
+ > double d = Convert.ToDouble(text);
122
+
123
+ >
124
+
125
+ > //数値 -> 文字列(先頭の0が消える)
126
+
127
+ > String text2 = d.ToString();
128
+
129
+ > txtDisplay.Text = text2;
130
+
131
+ > }
132
+
133
+ >
134
+
135
+ > enum sign { blank, ADD, SUB, MUL, DIV };
136
+
137
+ > sign exec = sign.blank;
138
+
139
+ >
140
+
141
+ > //クリア
142
+
143
+ > private void button_clear_Click(object sender, EventArgs e)
144
+
145
+ > {
146
+
147
+ > exec = sign.blank;
148
+
149
+ > txtDisplay.Text = "0";
150
+
151
+ > val1 = 0;
152
+
153
+ > isFirst = true;
154
+
155
+ > }
156
+
157
+ >
158
+
159
+ > //小数点
160
+
161
+ > private void button_dot_Click(object sender, EventArgs e)
162
+
163
+ > {
164
+
165
+ > //小数点の重複チェック
166
+
167
+ > if(txtDisplay.Text.IndexOf(".") >= 1)
168
+
169
+ > {
170
+
171
+ > //すでに小数点がある
172
+
173
+ > return;
174
+
175
+ > }
176
+
177
+ > txtDisplay.Text = txtDisplay.Text + ".";
178
+
179
+ >
180
+
181
+ > }
182
+
183
+ >
184
+
185
+ > //足し算。
186
+
187
+ > private void button_tasu_Click(object sender, EventArgs e)
188
+
189
+ > {
190
+
191
+ > if (!isFirst) calc();
192
+
193
+ > exec = sign.ADD;
194
+
195
+ > }
196
+
197
+ >
198
+
199
+ > //引き算。
200
+
201
+ > private void button_hiku_Click(object sender, EventArgs e)
202
+
203
+ > {
204
+
205
+ > if (!isFirst) calc();
206
+
207
+ > exec = sign.SUB;
208
+
209
+ > }
210
+
211
+ >
212
+
213
+ > //掛け算。
214
+
215
+ > private void button_kakuru_Click(object sender, EventArgs e)
216
+
217
+ > {
218
+
219
+ > if (!isFirst) calc();
220
+
221
+ > exec = sign.MUL;
222
+
223
+ > }
224
+
225
+ >
226
+
227
+ > //割り算。
228
+
229
+ > private void button_waru_Click(object sender, EventArgs e)
230
+
231
+ > {
232
+
233
+ > if (!isFirst) calc();
234
+
235
+ > exec = sign.DIV;
236
+
237
+ > }
238
+
239
+ >
240
+
241
+ > //イコール。
242
+
243
+ > private void button_wa_Click(object sender, EventArgs e)
244
+
245
+ > {
246
+
247
+ > calc();
248
+
249
+ > }
250
+
251
+ >
252
+
253
+ > private void calc()
254
+
255
+ > {
256
+
257
+ > double val2 = Convert.ToDouble(txtDisplay.Text);
258
+
259
+ > switch (exec)
260
+
261
+ > {
262
+
263
+ > case sign.ADD:
264
+
265
+ > val1 += val2;
266
+
267
+ > break;
268
+
269
+ > case sign.SUB:
270
+
271
+ > val1 -= val2;
272
+
273
+ > break;
274
+
275
+ > case sign.MUL:
276
+
277
+ > val1 *= val2;
278
+
279
+ > break;
280
+
281
+ > case sign.DIV:
282
+
283
+ > val1 /= val2;
284
+
285
+ > break;
286
+
287
+ > default:
288
+
289
+ > val1 = val2;
290
+
291
+ > break;
292
+
293
+ > }
294
+
295
+ >
296
+
297
+ > double result = Math.Truncate(val1 * 100.0) / 100.0;
298
+
299
+ >
300
+
301
+ > txtDisplay.Text = result.ToString();
302
+
303
+ > isFirst = true;
304
+
305
+ > }
306
+
307
+ > }
308
+
309
+ >
310
+
311
+ > }
312
+
313
+ ```