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 csharp_tt2
{
public partial class calculator : Form
{
String original_text;
string first_opernd;
string second_oprend;
String operator_used;
float result;
float second;
float first;
public calculator()
{
InitializeComponent();
}
private void button7_Click(object sender, EventArgs e)
{
String str = "5";
rtxt.Text += str;
}
private void calculator_Load(object sender, EventArgs e)
{
}
private void zero_Click(object sender, EventArgs e)
{
String str = "0";
rtxt.Text += str;
}
private void one_Click(object sender, EventArgs e)
{
String str = "1";
rtxt.Text += str;
}
private void Dot_Click(object sender, EventArgs e)
{
String str = ".";
rtxt.Text += str;
Dot.Enabled = false;
}
private void two_Click(object sender, EventArgs e)
{
String str = "2";
rtxt.Text += str;
}
private void three_Click(object sender, EventArgs e)
{
String str = "3";
rtxt.Text += str;
}
private void four_Click(object sender, EventArgs e)
{
String str = "4";
rtxt.Text += str;
}
private void six_Click(object sender, EventArgs e)
{
String str = "6";
rtxt.Text += str;
}
private void seven_Click(object sender, EventArgs e)
{
String str = "7";
rtxt.Text += str;
}
private void eight_Click(object sender, EventArgs e)
{
String str = "8";
rtxt.Text += str;
}
private void nine_Click(object sender, EventArgs e)
{
String str = "9";
rtxt.Text += str;
}
private void clear_Click(object sender, EventArgs e)
{
Dot.Enabled = true;
rtxt.Text = "";
first_opernd = "";
second_oprend = "";
}
private void addition_Click(object sender, EventArgs e)
{
first_opernd = rtxt.Text;
operator_used = "+";
rtxt.Text = "";
}
private void subtract_Click(object sender, EventArgs e)
{
first_opernd = rtxt.Text;
operator_used = "-";
rtxt.Text = "";
}
private void multiply_Click(object sender, EventArgs e)
{
first_opernd = rtxt.Text;
operator_used = "*";
rtxt.Text = "";
}
private void divide_Click(object sender, EventArgs e)
{
first_opernd = rtxt.Text;
operator_used = "/";
rtxt.Text = "";
}
private void equal_Click(object sender, EventArgs e)
{
switch(operator_used){
case "+":
second_oprend = rtxt.Text;
first = float.Parse(first_opernd);
second = float.Parse(second_oprend);
result = first + second;
rtxt.Text = result.ToString();
break;
case "-":
second_oprend = rtxt.Text;
first = float.Parse(first_opernd);
second = float.Parse(second_oprend);
result = first - second;
rtxt.Text = result.ToString();
break;
case "*":
second_oprend = rtxt.Text;
first = float.Parse(first_opernd);
second = float.Parse(second_oprend);
result = first * second;
rtxt.Text = result.ToString();
break;
case "/":
second_oprend = rtxt.Text;
if (second_oprend == "0")
{
rtxt.Text = "undifined error";
}
else
{
first = float.Parse(first_opernd);
second = float.Parse(second_oprend);
result = first / second;
rtxt.Text = result.ToString();
}
break;
}
}
}
}
Download full project