i我试图使用ComboBox在Windows表单计算器中使用平方根符号。请问我凌乱的代码:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
float x, y, z;
bool err = false;
x = int::Parse(textBox1->Text);
y = int::Parse(textBox3->Text);
if (comboBox1->SelectedItem->ToString() == "+") z = x + y;
else if (comboBox1->SelectedItem->ToString() == "-") z = x - y;
else if (comboBox1->SelectedItem->ToString() == "/") z = x / y;
else if (comboBox1->SelectedItem->ToString() == "*") z = x * y;
else if (comboBox1->SelectedItem->ToString() == "^") z = pow(x, y);
else if (comboBox1->SelectedItem->ToString() == "√") z = sqrt(x);
// if (comboBox1->SelectedItem->ToString() == "/" && y == 0) err = true;
if (err == true) textBox4->Text = "error";
else textBox4->Text = z.ToString();
}
I仅在代码和Combobox项目列表中使用Unicode符号。它应该通过
if
语句并简单地平方并给出x
,但是该程序只是没有计算任何内容。从我的猜测中,它不会传递z
语句,因为如果我用常规字符替换了平方根符号,则它可以很好地工作。
yes,该文件通过Unicode编码保存,因为它在启动时显示在我的程序上很好。
当它不是直接修复的情况下,我找到了利用SelectedIndex的解决方法,而不是比较Unicode字符,而是检查是否选择了该项目。在我的代码
中工作有缺陷if