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

質問編集履歴

1

コードをインデント

2020/03/12 08:09

投稿

Gunjirk
Gunjirk

スコア23

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