急!!为实现C# 计算器的连加(减乘除)

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += "1"; //输入数并在TEXTBOX1 上显示
}//由于问题补充百度不允许过长,将类似的省去(2,3,4等)
//
private void jia_Click(object sender, EventArgs e)
if (textBox1.TextLength > 0) //加法运算
YunSanFu = 1;
textBox1.Text = "";
textBox1.Focus();

} //
private void equar_Click(object sender, EventArgs e)
{
switch (YunSanFu) //等号运算 选择运算符
{
case 1:
textBox1.Text = Convert.ToString(n1 + Convert.ToDouble(textBox1.Text));
break;
case 2:
textBox1.Text = Convert.ToString(n1 - Convert.ToDouble(textBox1.Text));
break;
case 3:
textBox1.Text = Convert.ToString(n1 * Convert.ToDouble(textBox1.Text));
break;
case 4:
textBox1.Text = Convert.ToString(n1 / Convert.ToDouble(textBox1.Text));
break;
}
n1 = Convert.ToDouble(textBox1.Text); //结果重新赋值
//到第一个数
}我想使加减乘除后都把结果赋值到第一个数去,来实现连加连乘(例如1+1+1+1+1+1+1这样),谢谢,我日后学成也会尽量为别人服务!!
最新回答
呸狗屁的爱情っ

2024-09-25 06:39:46

using System;
using System.Collections.Generic;
using System.Text;
using Operation;

namespace OperationConsole
{
class Program
{
static void Main(string[] args)
{
try
{
//读入操作数和操作符
Console.Write("请输入数字A:");
string strNumberA = Console.ReadLine();
Console.Write("请选择运算符号(+、-、*、/):");
string strOperate = Console.ReadLine();
Console.Write("请输入数字B:");
string strNumberB = Console.ReadLine();

//进行计算
Operation.Operation oper;
oper = OperationFactory.createOperate(strOperate);
oper.NumberA = Convert.ToDouble(strNumberA);
oper.NumberB = Convert.ToDouble(strNumberB);
double result = oper.GetResult();
Console.WriteLine(result.ToString());
Console.Read();

}
catch
{
Console.Read();
}
}
}
}
傲慢多泪

2024-09-25 09:00:11

你遇到什么问题了?