各位大虾看看,我这么写根本就不跟我小数点的概念~~~~~~很是郁闷了,还有怎么能实现打印结果为 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)
{ } }
}
现在输入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)
{ } }
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货