C#電卓のプログラムを作成しています。
10+=と入力すると答えが20になってしまします
答えが10になるようにソースコードを変更したいのですがどのように変更すればよろしいでしょうか?```ここに言語を入力
コード
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 電卓
{
public partial class Form1 : Form
{
string str_first;
string str_mark;
double first;
double kazu;
Boolean clearflag = true;
Boolean secondflag = false;
public Form1() { InitializeComponent(); } private void button6_Click(object sender, EventArgs e) { tb_kazu.Text = "表示"; } private void btMpura_Click(object sender, EventArgs e) { tb_kazu.Text = "M+"; } private void button8_Click(object sender, EventArgs e) { tb_kazu.Text = "M-"; } private void btpacent_Click(object sender, EventArgs e) { tb_kazu.Text = "%+-"; } private void button15_Click(object sender, EventArgs e) { tb_kazu.Text = "→"; } private void btCIC_Click(object sender, EventArgs e) { tb_kazu.Text = "CI/ C"; } private void btRMCM_Click(object sender, EventArgs e) { tb_kazu.Text = "RM/CM"; } private void btoku_Click(object sender, EventArgs e) { tb_kazu.Text = "億"; } private void btman_Click(object sender, EventArgs e) { tb_kazu.Text = "万"; } private void btsen_Click(object sender, EventArgs e) { tb_kazu.Text = "千"; } private void btpuramai_Click(object sender, EventArgs e) { tb_kazu.Text = "→+-←"; } private void btzeikomi_Click(object sender, EventArgs e) { tb_kazu.Text = "税込"; } private void btzeinuki_Click(object sender, EventArgs e) { tb_kazu.Text = "税抜"; } private void bt0_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } tb_kazu.Text = tb_kazu.Text + "0"; } private void bt00_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } if (tb_kazu.Text == "0") { } else { tb_kazu.Text = tb_kazu.Text + "00"; } } private void button23_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } tb_kazu.Text = tb_kazu.Text + "1"; } private void bt2_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } tb_kazu.Text = tb_kazu.Text + "2"; } private void bt3_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } tb_kazu.Text = tb_kazu.Text + "3"; } private void bt4_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } tb_kazu.Text = tb_kazu.Text + "4"; } private void bt5_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } tb_kazu.Text = tb_kazu.Text + "5"; } private void bt6_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } tb_kazu.Text = tb_kazu.Text + "6"; } private void bt7_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } tb_kazu.Text = tb_kazu.Text + "7"; } private void button18_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } tb_kazu.Text = tb_kazu.Text + "8"; } private void bt9_Click(object sender, EventArgs e) { if (clearflag == true) { tb_kazu.Text = ""; clearflag = false; } tb_kazu.Text = tb_kazu.Text + "9"; } private void btCA_Click(object sender, EventArgs e) { tb_kazu.Text = ""; textBox2.Text = ""; tb_kazu.Text = "0"; clearflag = true; } private void btcon_Click(object sender, EventArgs e) { if (clearflag == true) { clearflag = false; } if (tb_kazu.Text.IndexOf(".") < 0 )
{
tb_kazu.Text = tb_kazu.Text + ".";
}
} private void btplus_Click(object sender, EventArgs e) { textBox2.Text = "+"; { //テキストボックス2に+を表示させる first = double.Parse(tb_kazu.Text); str_mark = textBox2.Text; clearflag = true; // secondflag = true; } } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btmainasu_Click(object sender, EventArgs e) { textBox2.Text = "-"; str_mark = textBox2.Text; first = double.Parse(tb_kazu.Text); str_mark = textBox2.Text; clearflag = true; secondflag = true; } private void btkakeru_Click(object sender, EventArgs e) { textBox2.Text = "×"; str_mark = textBox2.Text; first = double.Parse(tb_kazu.Text); str_mark = textBox2.Text; clearflag = true; secondflag = true; } private void button30_Click(object sender, EventArgs e) { textBox2.Text = "÷"; first = int.Parse(tb_kazu.Text); str_mark = textBox2.Text; clearflag = true; secondflag = true; } /// <summary> /// btwa_Click "="ボタンを押したときの処理 /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btwa_Click(object sender, EventArgs e) { textBox2.Text = "="; clearflag = true; kazu = double.Parse(tb_kazu.Text); // Calculation(); if (secondflag == true) //secondが必要か不必要かの確認 { if(str_mark == "+") { tb_kazu.Text = (first + kazu).ToString(); } else if (str_mark == "-") { tb_kazu.Text = (first - kazu).ToString(); } else if (str_mark == "×") { tb_kazu.Text = (first * kazu).ToString(); } else if (str_mark == "÷") { tb_kazu.Text = (first / kazu).ToString(); } } else { tb_kazu.Text = first.ToString(); } } private void textBox2_TextChanged(object sender, EventArgs e) { } private void Calculation() { } }
}
あなたの回答
tips
プレビュー