Исправить программу простого калькулятора. C++ Windows Forms
Некорректно работают операции (+-/*), если после каждой операции нажимать "=", то считает правильно, но если, к примеру 2*11 нажать "=", потом два раза добавить +2 +2, то выведет 4, вместо 26.
Нужно, чтобы калькулятор суммировал столько раз, сколько надо, и при нажатии на кнопку "=", выводило правильный ответ.
#pragma endregion
C++ |
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
| double FirstValue;
char arithm;
private: System::Void button25_Click(System::Object^ sender, System::EventArgs^ e)
{//РЕЗУЛЬТАТ
// переменная второго числа
// переменная результата
double SecondValue;
double outcome;
SecondValue = Convert::ToDouble(textBox1->Text);
// если нажата кнопка сложения arithmetic получит значение
// +, в результате выполниться код из скобок
if (arithm == '+')
{
outcome = (FirstValue + SecondValue);
textBox1->Text = Convert::ToString(outcome);
FirstValue = outcome;
}
if (arithm == '-')
{
outcome = (FirstValue - SecondValue);
textBox1->Text = Convert::ToString(outcome);
FirstValue = outcome;
}
if (arithm == '*')
{
outcome = (FirstValue * SecondValue);
textBox1->Text = Convert::ToString(outcome);
FirstValue = outcome;
}
if (arithm == '/')
{
if (SecondValue == 0)
{
textBox1->Text = "НЕ ДОПУСТИМАЯ ОПЕРАЦИЯ";
}
else
{
outcome = FirstValue / SecondValue;
textBox1->Text = Convert::ToString(outcome);
FirstValue = outcome;
}
}
}
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {//сумма
FirstValue= Convert::ToDouble(textBox1->Text);
textBox1->Text = "0";
arithm = '+';
}
private: System::Void button19_Click(System::Object^ sender, System::EventArgs^ e) {
FirstValue = Convert::ToDouble(textBox1->Text);
textBox1->Text = "0";
arithm = '-';
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
FirstValue = Convert::ToDouble(textBox1->Text);
textBox1->Text = "0";
arithm = '/';
}
private: System::Void button18_Click(System::Object^ sender, System::EventArgs^ e) {
FirstValue = Convert::ToDouble(textBox1->Text);
textBox1->Text = "0";
arithm = '*';
}
private: System::Void button15_Click(System::Object^ sender, System::EventArgs^ e) {
textBox1->Text = textBox1->Text + 0;
}
private: System::Void button12_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox1->Text == "0" && textBox1->Text != nullptr)
textBox1->Text = "1";
else
textBox1->Text = textBox1->Text + 1;
}
private: System::Void button11_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox1->Text == "0" && textBox1->Text != nullptr)
textBox1->Text = "2";
else
textBox1->Text = textBox1->Text + 2;
}
private: System::Void button10_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox1->Text == "0" && textBox1->Text != nullptr)
textBox1->Text = "3";
else
textBox1->Text = textBox1->Text + 3;
}
private: System::Void button8_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox1->Text == "0" && textBox1->Text != nullptr)
textBox1->Text = "4";
else
textBox1->Text = textBox1->Text + 4;
}
private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox1->Text == "0" && textBox1->Text != nullptr)
textBox1->Text = "5";
else
textBox1->Text = textBox1->Text + 5;
}
private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox1->Text == "0" && textBox1->Text != nullptr)
textBox1->Text = "6";
else
textBox1->Text = textBox1->Text + 6;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox1->Text == "0" && textBox1->Text != nullptr)
textBox1->Text = "7";
else
textBox1->Text = textBox1->Text + 7;
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox1->Text == "0" && textBox1->Text != nullptr)
textBox1->Text = "8";
else
textBox1->Text = textBox1->Text + 8;
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox1->Text == "0" && textBox1->Text != nullptr)
textBox1->Text = "9";
else
textBox1->Text = textBox1->Text + 9;
}
private: System::Void button14_Click(System::Object^ sender, System::EventArgs^ e) {
textBox1->Text = textBox1->Text + ".";
}
private: System::Void button17_Click(System::Object^ sender, System::EventArgs^ e) {
textBox1->Text = "0";
}
};
} |
|