c#新手计算器求助!!!
这是我用窗体编的计算器代码,计算结果都不对,求解释,有附件(只编到计算的...)
ex4.rar
(38.16 KB)
namespace ex4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
textBox1.Text = textBox1.Text + btn.Text;
}
string a ;
string f;
int num1;
private void button14_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
a = textBox1.Text;
num1 = Convert.ToInt32(a);
textBox1.Text = "";
f = btn.Text;
}
private void button18_Click(object sender, EventArgs e)
{
if (f == "+")
{
int c = num1 + Convert.ToInt32(a);
textBox1.Text = Convert.ToString(c);
}
else if (f == "-")
{
int c = num1 - Convert.ToInt32(a);
textBox1.Text = Convert.ToString(c);
}
else if (f == "*")
{
int c = num1 * Convert.ToInt32(a);
textBox1.Text = Convert.ToString(c);
}
else if (f == "/")
{
int c = num1 / Convert.ToInt32(a);
textBox1.Text = Convert.ToString(c);
}
}
}
}