-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBITS24C05.cs
200 lines (171 loc) · 5.76 KB
/
BITS24C05.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System.Data;
using System.Windows.Forms;
namespace BITS24C05
{
public partial class BITS24C05 : Form
{
bool pwCal = false;
bool AddCal = false;
bool SubCal = false;
bool MultiCal = false;
bool DivCal = false;
public BITS24C05()
{
InitializeComponent();
}
private void BITS24C05_Load(object sender, EventArgs e)
{
}
private void calculateBtn_Click(object sender, EventArgs e)
{
if (checkForErrors()) { return; }
if (pwCal)
{
string[] splitinput = inputTxt.Text.Split('^');
clearBtn_Click(sender, e);
double num1 = double.Parse(splitinput[0]);
double num2 = double.Parse(splitinput[1]);
inputTxt.Text = Math.Pow(num1, num2).ToString();
pwCal = false;
}
if (AddCal)
{
string[] splitinput = inputTxt.Text.Split('+');
clearBtn_Click(sender, e);
double num1 = double.Parse(splitinput[0]);
double num2 = double.Parse(splitinput[1]);
inputTxt.Text = (num1 + num2).ToString();
AddCal = false;
}
if (SubCal)
{
string[] splitinput = inputTxt.Text.Split('-');
clearBtn_Click(sender, e);
double num1 = double.Parse(splitinput[0]);
double num2 = double.Parse(splitinput[1]);
inputTxt.Text = (num1 - num2).ToString();
SubCal = false;
}
if (MultiCal)
{
string[] splitinput = inputTxt.Text.Split('*');
clearBtn_Click(sender, e);
double num1 = double.Parse(splitinput[0]);
double num2 = double.Parse(splitinput[1]);
inputTxt.Text = (num1 * num2).ToString();
MultiCal = false;
}
if (DivCal)
{
string[] splitinput = inputTxt.Text.Split('/');
clearBtn_Click(sender, e);
double num1 = double.Parse(splitinput[0]);
double num2 = double.Parse(splitinput[1]);
inputTxt.Text = (num1 / num2).ToString();
DivCal = false;
}
}
private void addBtn_Click(object sender, EventArgs e)
{
inputTxt.Text += "+";
AddCal = true;
}
private void subBtn_Click(object sender, EventArgs e)
{
inputTxt.Text += "-";
SubCal = true;
}
private void mutiBtn_Click(object sender, EventArgs e)
{
inputTxt.Text += "*";
MultiCal = true;
}
private void divideBtn_Click(object sender, EventArgs e)
{
inputTxt.Text += "/";
DivCal = true;
}
private void clearBtn_Click(object sender, EventArgs e)
{
inputTxt.Text = null;
}
private void rootBtn_Click(object sender, EventArgs e)
{
if (checkForErrors()) { return; }
double result = double.Parse(inputTxt.Text);
result = Math.Sqrt(result);
inputTxt.Text = result.ToString();
}
private void powerBtn_Click(object sender, EventArgs e)
{
inputTxt.Text += "^";
pwCal = true;
}
private void btn0_Click(object sender, EventArgs e)
{
inputTxt.Text += "0";
}
private void btn1_Click(object sender, EventArgs e)
{
inputTxt.Text += "1";
}
private void btn2_Click(object sender, EventArgs e)
{
inputTxt.Text += "2";
}
private void btn3_Click(object sender, EventArgs e)
{
inputTxt.Text += "3";
}
private void btn4_Click(object sender, EventArgs e)
{
inputTxt.Text += "4";
}
private void btn5_Click(object sender, EventArgs e)
{
inputTxt.Text += "5";
}
private void btn6_Click(object sender, EventArgs e)
{
inputTxt.Text += "6";
}
private void btn7_Click(object sender, EventArgs e)
{
inputTxt.Text += "7";
}
private void btn8_Click(object sender, EventArgs e)
{
inputTxt.Text += "8";
}
private void btn9_Click(object sender, EventArgs e)
{
inputTxt.Text += "9";
}
private void dotBtn_Click(object sender, EventArgs e)
{
inputTxt.Text += ".";
}
private void inputTxt_TextChanged(object sender, EventArgs e)
{
if (inputTxt.Text.Contains('^')) { pwCal = true; }
else { pwCal = false; }
if (inputTxt.Text.Contains('+')) { AddCal = true; }
else { AddCal = false; }
if (inputTxt.Text.Contains('-')) { SubCal = true; }
else { SubCal = false; }
if (inputTxt.Text.Contains('*')) { MultiCal = true; }
else { MultiCal = false; }
if (inputTxt.Text.Contains('/')) { DivCal = true; }
else { DivCal = false; }
}
private bool checkForErrors()
{
var match = inputTxt.Text.IndexOfAny("1234567890+-*/^".ToCharArray()) != -1;
if (match)
{
MessageBox.Show("E01 : Invalid Character(s)!");
}
return match;
}
}
}