热烈欢迎。《关于C#计算器地,为什么算出结果不对》
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 计算器
{
public partial class Form1 : Form
{
double num1=0,num2 = 0, num3 = 0, num4=0,num5=0,num6=0;
char a;
public Form1()
{
InitializeComponent();
}
private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void b1_Click(object sender, EventArgs e)
{
textBox1.Text += ((Button)sender).Text;
num1 = Double.Parse(textBox1.Text);
}
private void b13_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
//textBox1.Text ="+";
a = '+';
}
private void b14_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
//textBox1.Text ="-";
a = '-';
}
private void b15_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
//textBox1.Text ="*";
a = '*';
}
private void b16_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
//textBox1.Text = "/";
a = '/';
}
private void b12_Click(object sender, EventArgs e)
{
num2=Double.Parse(textBox1.Text);
switch (a)
{
case '+':
{
if(num3!=0)
num1 = num3;
num3 = num1 + num2;
textBox1.Text = num3.ToString();
} break;
case '-':
{
if (num4!=0)
num1 = num4;
num4 = num1 - num2;
textBox1.Text = num4.ToString();
} break;
case '*':
{
if (num5 != 0)
num1 = num5;
num5 = num1 * num2;
textBox1.Text = num5.ToString();
} break;
case '/':
{
if (num6 != 0)
num1 = num6;
num6 = num1 / num2;
textBox1.Text = num6.ToString();
} break;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
time.Text = string.Format("现在时间: {0}", DateTime.Now);
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
}
}
}