質問編集履歴
1
コードをインデント
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -19,137 +19,139 @@
|
|
|
19
19
|
不明点あれば、何でも答えます。
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
using System;
|
|
23
|
-
using System.Collections.Generic;
|
|
24
|
-
using System.ComponentModel;
|
|
25
|
-
using System.Data;
|
|
26
|
-
using System.Drawing;
|
|
27
|
-
using System.Linq;
|
|
28
|
-
using System.Text;
|
|
29
|
-
using System.Threading.Tasks;
|
|
30
|
-
using System.Windows.Forms;
|
|
31
22
|
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
23
|
+
> using System;
|
|
24
|
+
> using System.Collections.Generic;
|
|
25
|
+
> using System.ComponentModel;
|
|
26
|
+
> using System.Data;
|
|
27
|
+
> using System.Drawing;
|
|
28
|
+
> using System.Linq;
|
|
29
|
+
> using System.Text;
|
|
30
|
+
> using System.Threading.Tasks;
|
|
31
|
+
> using System.Windows.Forms;
|
|
32
|
+
>
|
|
33
|
+
> namespace WindowsFormsApp1
|
|
34
|
+
> {
|
|
35
|
+
> public partial class Form1 : Form
|
|
36
|
+
> {
|
|
37
|
+
>
|
|
38
|
+
> public Form1()
|
|
39
|
+
> {
|
|
40
|
+
> InitializeComponent();
|
|
41
|
+
> }
|
|
42
|
+
>
|
|
43
|
+
> bool isFirst = true;
|
|
44
|
+
> double val1 = 0;
|
|
45
|
+
>
|
|
46
|
+
> private void Form1_Load(object sender, EventArgs e)
|
|
47
|
+
> {
|
|
48
|
+
>
|
|
49
|
+
> }
|
|
50
|
+
>
|
|
51
|
+
> private void btnNumber_Click(object sender, EventArgs e)
|
|
52
|
+
> {
|
|
53
|
+
> if (isFirst)
|
|
54
|
+
> {
|
|
55
|
+
> txtDisplay.Text = "";
|
|
56
|
+
> isFirst = false;
|
|
57
|
+
> }
|
|
58
|
+
> String text = txtDisplay.Text + ((Button)sender).Text;
|
|
59
|
+
>
|
|
60
|
+
> //文字列 -> 数値
|
|
61
|
+
> double d = Convert.ToDouble(text);
|
|
62
|
+
>
|
|
63
|
+
> //数値 -> 文字列(先頭の0が消える)
|
|
64
|
+
> String text2 = d.ToString();
|
|
65
|
+
> txtDisplay.Text = text2;
|
|
66
|
+
> }
|
|
67
|
+
>
|
|
68
|
+
> enum sign { blank, ADD, SUB, MUL, DIV };
|
|
69
|
+
> sign exec = sign.blank;
|
|
70
|
+
>
|
|
71
|
+
> //クリア
|
|
72
|
+
> private void button_clear_Click(object sender, EventArgs e)
|
|
73
|
+
> {
|
|
74
|
+
> exec = sign.blank;
|
|
75
|
+
> txtDisplay.Text = "0";
|
|
76
|
+
> val1 = 0;
|
|
77
|
+
> isFirst = true;
|
|
78
|
+
> }
|
|
79
|
+
>
|
|
80
|
+
> //小数点
|
|
81
|
+
> private void button_dot_Click(object sender, EventArgs e)
|
|
82
|
+
> {
|
|
83
|
+
> //小数点の重複チェック
|
|
84
|
+
> if(txtDisplay.Text.IndexOf(".") >= 1)
|
|
85
|
+
> {
|
|
86
|
+
> //すでに小数点がある
|
|
87
|
+
> return;
|
|
88
|
+
> }
|
|
89
|
+
> txtDisplay.Text = txtDisplay.Text + ".";
|
|
90
|
+
>
|
|
91
|
+
> }
|
|
92
|
+
>
|
|
93
|
+
> //足し算。
|
|
94
|
+
> private void button_tasu_Click(object sender, EventArgs e)
|
|
95
|
+
> {
|
|
96
|
+
> if (!isFirst) calc();
|
|
97
|
+
> exec = sign.ADD;
|
|
98
|
+
> }
|
|
99
|
+
>
|
|
100
|
+
> //引き算。
|
|
101
|
+
> private void button_hiku_Click(object sender, EventArgs e)
|
|
102
|
+
> {
|
|
103
|
+
> if (!isFirst) calc();
|
|
104
|
+
> exec = sign.SUB;
|
|
105
|
+
> }
|
|
106
|
+
>
|
|
107
|
+
> //掛け算。
|
|
108
|
+
> private void button_kakuru_Click(object sender, EventArgs e)
|
|
109
|
+
> {
|
|
110
|
+
> if (!isFirst) calc();
|
|
111
|
+
> exec = sign.MUL;
|
|
112
|
+
> }
|
|
113
|
+
>
|
|
114
|
+
> //割り算。
|
|
115
|
+
> private void button_waru_Click(object sender, EventArgs e)
|
|
116
|
+
> {
|
|
117
|
+
> if (!isFirst) calc();
|
|
118
|
+
> exec = sign.DIV;
|
|
119
|
+
> }
|
|
120
|
+
>
|
|
121
|
+
> //イコール。
|
|
122
|
+
> private void button_wa_Click(object sender, EventArgs e)
|
|
123
|
+
> {
|
|
124
|
+
> calc();
|
|
125
|
+
> }
|
|
126
|
+
>
|
|
127
|
+
> private void calc()
|
|
128
|
+
> {
|
|
129
|
+
> double val2 = Convert.ToDouble(txtDisplay.Text);
|
|
130
|
+
> switch (exec)
|
|
131
|
+
> {
|
|
132
|
+
> case sign.ADD:
|
|
133
|
+
> val1 += val2;
|
|
134
|
+
> break;
|
|
135
|
+
> case sign.SUB:
|
|
136
|
+
> val1 -= val2;
|
|
137
|
+
> break;
|
|
138
|
+
> case sign.MUL:
|
|
139
|
+
> val1 *= val2;
|
|
140
|
+
> break;
|
|
141
|
+
> case sign.DIV:
|
|
142
|
+
> val1 /= val2;
|
|
143
|
+
> break;
|
|
144
|
+
> default:
|
|
145
|
+
> val1 = val2;
|
|
146
|
+
> break;
|
|
147
|
+
> }
|
|
148
|
+
>
|
|
149
|
+
> double result = Math.Truncate(val1 * 100.0) / 100.0;
|
|
150
|
+
>
|
|
151
|
+
> txtDisplay.Text = result.ToString();
|
|
152
|
+
> isFirst = true;
|
|
153
|
+
> }
|
|
154
|
+
> }
|
|
155
|
+
>
|
|
156
|
+
> }
|
|
157
|
+
```
|