帮忙完善一下这个计算器,谢谢!

来源:百度知道 编辑:UC知道 时间:2024/06/20 16:46:46
这是个最基本的计算器代码,是用visual studio2005编的windows应用程序。
1个textBox控件,16个button控件(10个数字,4个运算符,1个等号,1个清零)。
帮忙完善一下这些代码,例如:用户如果先点“+”号,就要提示他先点完数字才能点运算符;如果连续点两个运算符就提示不能这样做;等等……
越完善越好,满意给您追加100分。。。。。。。

int x1, x2;
double x;
string c;
private void sz_button(int n)
{
if (c == null) x1 = x1 * 10 + n;
else x2 = x2 * 10 + n;
textBox1.Text += n;
}

private void ysf_button(string m)
{
c = m;
textBox1.Text += m;
}

private void button1_Click(object sender, EventArgs e)
{
sz_button(1);
}

private void button2_Click(object sender, EventArgs e)
{
sz_button(2);
}

private void button3_Click(object sender, EventArgs e)
{
sz_

刚写的...你要求的都实现了,还有一个连续计算没有实现,就是说不可以 1+2+3+4,但是可以1+2=再+3

0-9数字按钮触发同一个事件,4操作符也公用一个事件

还有4个全局变量firstnum, lastnum用来储存第一个和第二个数,opera储存操作符,stat储存当前状态

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
string stat = "EndReadNum";//StartReadNum,EndReadNum,Counted
string firstnum = null, lastnum = null;
string opera = null;

public Form1()
{
InitializeComponent();
}

//清零按钮
private void buttonClear_Click(object sender, EventArgs e)
{
label1.Text = "";
textBox1.Text = "0";
stat = "EndReadNum&quo