私は一生、入力を連続して表示し、次にこの数値の出力を表示する方法を理解できません。
数値をどこかに保存してから表示するにはどうしますか? 私は非常に多くのサークルに参加したため、自分自身を混乱させて忘却しました。何をする必要があるかはわかっていますが、どのように、または正確にどこでそれを行うべきかはわかりません。
public partial class Form1 : Form
{
char c;
double num1;
double num2;
public Form1()
{
InitializeComponent();
}
private void btn0_Click(object sender, EventArgs e)
{
txtBox.Text += 0;
}
private void btn1_Click(object sender, EventArgs e)
{
txtBox.Text += 1;
}
private void btn2_Click(object sender, EventArgs e)
{
txtBox.Text += 2;
}
private void btn3_Click(object sender, EventArgs e)
{
txtBox.Text += 3;
}
private void btn4_Click(object sender, EventArgs e)
{
txtBox.Text += 4;
}
private void btn5_Click(object sender, EventArgs e)
{
txtBox.Text += 5;
}
private void btn6_Click(object sender, EventArgs e)
{
txtBox.Text += 6;
}
private void btn7_Click(object sender, EventArgs e)
{
txtBox.Text += 7;
}
private void btn8_Click(object sender, EventArgs e)
{
txtBox.Text += 8;
}
private void btn9_Click(object sender, EventArgs e)
{
txtBox.Text += 9;
}
private void btnDecimal_Click(object sender, EventArgs e)
{
if (!txtBox.Text.Contains('.'))
txtBox.Text += '.';
}
private void btnAddition_Click(object sender, EventArgs e)
{
c = '+';
num1 = double.Parse(txtBox.Text);
txtBox.Text = string.Empty;
}
private void btnSubtraction_Click(object sender, EventArgs e)
{
c = '-';
num1 = double.Parse(txtBox.Text);
txtBox.Text = string.Empty;
}
private void btnMultiplication_Click(object sender, EventArgs e)
{
c = '*';
num1 = double.Parse(txtBox.Text);
txtBox.Text = string.Empty;
}
private void btnDivision_Click(object sender, EventArgs e)
{
c = '/';
num1 = double.Parse(txtBox.Text);
txtBox.Text = string.Empty;
}
private void btnClear_Click(object sender, EventArgs e)
{
txtBox.Clear();
}
private void btnEqual_Click(object sender, EventArgs e)
{
num2 = double.Parse(txtBox.Text);
double result;
switch (c)
{
case '+':
result = num1 + num2;
txtBox.Text = result.ToString();
break;
case '-':
result = num1 - num2;
txtBox.Text = result.ToString();
break;
case '/':
if (num2 != 0)
{
result = num1 / num2;
txtBox.Text = result.ToString();
}
else
{
txtBox.Text = "You can't divide by zero... sign up for Math 100 please =)";
}
break;
case '*':
result = num1 * num2;
txtBox.Text = result.ToString();
break;
}
}
}
}