C#项目简单计算器 [英] c# project simple calculator
问题描述
我正在C#Visual Express 2013中构建一个非常简单的计算器.我正在看一本书.这里是第一周的编码器.
I am building a very simple calculator in C# Visual Express 2013. I am following a book. First week coder here.
http://www.homeandlearn.co.uk/csharp/calculator1.txt
在上面编写的代码中,我看不懂其中的一段代码:
In the code written above I do not understand one piece of code:
private void btnClear_Click(object sender, EventArgs e)
{
plusButtonClicked = false;
minusButtonClicked = false;
divideButtonClicked = true;
multiplyButtonClicked = false;
txtDisplay.Clear();
}
在这里拥有这些布尔值的附加价值是什么?仅编写 txtDisplay.Clear();
不足以使 btnClear_Click
执行计算器的行为吗?
What is the added value of having these booleans here? Is only writing txtDisplay.Clear();
not enough for the btnClear_Click
to perform behaviour of a calculator?
推荐答案
请参阅平等按钮":
private void btnEquals_Click(object sender, EventArgs e) {
if (plusButtonClicked == true) {
total2 = total1 + double.Parse(txtDisplay.Text);
}
else if (minusButtonClicked == true) {
total2 = total1 - double.Parse(txtDisplay.Text);
}
else if (multiplyButtonClicked == true) {
total2 = total1 * double.Parse(txtDisplay.Text);
}
else if (divideButtonClicked == true) {
total2 = total1 / double.Parse(txtDisplay.Text);
}
txtDisplay.Text = total2.ToString();
total1 = 0;
}
开发人员想知道用户是否单击了equal按钮,程序应该怎么做....就像一个真正的计算器一样.但是对于清除按钮,所有标志都应设置为 false
.
The developer wants to know if the user clicked on equal button , what should the program do .... just like a real calculator.
But for the clear button All of the flags should be set to false
.
这篇关于C#项目简单计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!