读书人

C#简单计算器怎么实现小数点运算~望各

发布时间: 2012-04-09 13:41:25 作者: rapoo

C#简单计算器如何实现小数点运算~望各位大虾帮忙解答
各位大虾看看,我这么写根本就不跟我小数点的概念~~~~~~很是郁闷了,还有怎么能实现打印结果为 2+3=5!
现在输入2显示(2),+显示空白,3只显示(3),=只显示(5);
想要输入2显示(2),接着输入+显示(2+),输入3显示(2+3),输入=显示(2+3=5);


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

namespace calc
{
public partial class Form1 : Form
{
int a = 0;
int b = 0;
double result = 0.0;
char c;
bool joiy = true;

public Form1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
Console.WriteLine(a);
}

private void button16_Click(object sender, EventArgs e)
{
if (joiy == false)
{
b = (int)result;
joiy = true;
}
else
{
if (b == 0)
{
b = a;
}
else
{
b -= a;
}
}
a = 0;
this.textBox1.Text = "";
c = '_';
}

private void button17_Click(object sender, EventArgs e)
{
if (joiy == false)
{
b = (int)result;
joiy = true;
}
else
{
if (b == 0)
{
b = a;
}
else
{
b += a;
}
}
a = 0;
this.textBox1.Text = "";
c = '+';
}

private void button14_Click(object sender, EventArgs e)
{
if (joiy == false)
{
b = (int)result;
joiy = true;
}
else
{
if (b == 0)
{
b = a;
}
else
{
b *= a;
}
}
a = 0;
this.textBox1.Text = "";
c='*';
}

private void button15_Click(object sender, EventArgs e)
{
if (joiy == false)
{
b = (int)result;
joiy = true;
}
else
{
if (b == 0)
{
b = a;
}
else
{
b /= a;
}
}
a = 0;
this.textBox1.Text = "";
c='/';
}

private void button1_Click(object sender, EventArgs e)


{
joiy = true;
a = 10 * a + int.Parse(button1.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button2_Click(object sender, EventArgs e)
{
joiy = true;
a = 10 * a + int.Parse(button2.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button3_Click(object sender, EventArgs e)
{
joiy = true;
a = 10 * a + int.Parse(button3.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button4_Click(object sender, EventArgs e)
{
joiy = true;
a = 10 * a + int.Parse(button4.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button5_Click(object sender, EventArgs e)
{
joiy = true;
a = 10 * a + int.Parse(button5.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button6_Click(object sender, EventArgs e)
{
joiy = true;
a = 10 * a + int.Parse(button6.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button7_Click(object sender, EventArgs e)
{
joiy = true;
a = 10 * a + int.Parse(button7.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button8_Click(object sender, EventArgs e)
{
joiy = true;
a = 10 * a + int.Parse(button8.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button9_Click(object sender, EventArgs e)
{
joiy = true;
a = 10 * a + int.Parse(button9.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button10_Click(object sender, EventArgs e)
{
joiy = true;
a = 10 * a + int.Parse(button10.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button11_Click(object sender, EventArgs e)//button11为小数点
{
joiy = true;
a = 10 * a + int.Parse(button11.Text.ToString());
this.textBox1.Text = a.ToString();
}

private void button12_Click(object sender, EventArgs e)
{
joiy = false;
if (c == '+')
{
result = a + b;
}
if (c == '-')
{
result = b - a;
}
if (c == '*')
{
result = a * b;
}
if (c == '/')
{
result = (double)b / ((double)a);
}
a = 0;
b = 0;
this.textBox1.Text = result.ToString();

}

private void button13_Click(object sender, EventArgs e)
{
a = 0;
b = 0;
this.textBox1.Text = a.ToString();


}

private void Form1_Load(object sender, EventArgs e)
{

}

}
}


[解决办法]
c#计算器的源代码
[解决办法]
http://topic.csdn.net/u/20110430/02/a3a306f8-2e21-4271-b3c5-35e2018933be.html
[解决办法]
LZ,还不如用多态的方法呢,我看你代码看的有点头晕。。。。你这。。。面向对象编程。。。

读书人网 >C#

热点推荐