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 WindowsFormsApp1
{
public partial class Form1 : Form
{
String oper="";
double currentNumber = 0;
double savedNumber = 0;
public Form1()
{
InitializeComponent();
}
private void calcOper(ref String oper, ref double savedNumber, ref double currentNumber)
{
if (oper == "+") savedNumber += currentNumber;
else if (oper == "-") savedNumber -= currentNumber;
else if (oper == "*") savedNumber *= currentNumber;
else if (oper == "/") savedNumber /= currentNumber;
else savedNumber = currentNumber;
}
private void button1_Click(object sender, EventArgs e)
{
calcOper(ref oper, ref savedNumber, ref currentNumber);
rbx1.Text = savedNumber.ToString();
oper = "=";
question.Text += currentNumber;
currentNumber = 0;
currentNumber = savedNumber;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
if (currentNumber != 0)
{
calcOper(ref oper, ref savedNumber, ref currentNumber);
question.Text += currentNumber.ToString() + "+";
rbx1.Text = savedNumber.ToString();
currentNumber = 0;
oper = "+";
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void rbx1_TextChanged(object sender, EventArgs e)
{
}
private void num1_Click(object sender, EventArgs e)
{
currentNumber = (currentNumber * 10) + 1;
rbx1.Text = currentNumber.ToString();
}
private void minus_Click(object sender, EventArgs e)
{
if (currentNumber != 0)
{
calcOper(ref oper, ref savedNumber, ref currentNumber);
question.Text += currentNumber.ToString() + "-";
rbx1.Text = savedNumber.ToString();
currentNumber = 0;
oper = "-";
}
}
private void clear_Click(object sender, EventArgs e)
{
rbx1.Clear();
question.Clear();
savedNumber = 0;
currentNumber = 0;
}
private void mul_Click(object sender, EventArgs e)
{
if (currentNumber != 0)
{
calcOper(ref oper, ref savedNumber, ref currentNumber);
question.Text += currentNumber.ToString() + "*";
rbx1.Text = savedNumber.ToString();
currentNumber = 0;
oper = "*";
}
}
private void div_Click(object sender, EventArgs e)
{
if (currentNumber != 0)
{
calcOper(ref oper, ref savedNumber, ref currentNumber);
question.Text += currentNumber.ToString() + "/";
rbx1.Text = savedNumber.ToString();
currentNumber = 0;
oper = "/";
}
}
private void num3_Click(object sender, EventArgs e)
{
currentNumber = (currentNumber * 10) + 3;
rbx1.Text = currentNumber.ToString();
}
private void num4_Click(object sender, EventArgs e)
{
currentNumber = (currentNumber * 10) + 4;
rbx1.Text = currentNumber.ToString();
}
private void num5_Click(object sender, EventArgs e)
{
currentNumber = (currentNumber * 10) + 5;
rbx1.Text = currentNumber.ToString();
}
private void num6_Click(object sender, EventArgs e)
{
currentNumber = (currentNumber * 10) + 6;
rbx1.Text = currentNumber.ToString();
}
private void num7_Click(object sender, EventArgs e)
{
currentNumber = (currentNumber * 10) + 7;
rbx1.Text = currentNumber.ToString();
}
private void num8_Click(object sender, EventArgs e)
{
currentNumber = (currentNumber * 10) + 8;
rbx1.Text = currentNumber.ToString();
}
private void num9_Click(object sender, EventArgs e)
{
currentNumber = (currentNumber * 10) + 9;
rbx1.Text = currentNumber.ToString();
}
private void num0_Click(object sender, EventArgs e)
{
currentNumber = (currentNumber * 10) + 0;
rbx1.Text = currentNumber.ToString();
}
private void num2_Click(object sender, EventArgs e)
{
currentNumber = (currentNumber * 10) + 2;
rbx1.Text = currentNumber.ToString();
}
private void question_TextChanged(object sender, EventArgs e)
{
}
}
}