Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views7 pages

Calculator

The document is a C# code for a simple calculator application using Windows Forms. It includes functionalities for basic arithmetic operations, square root, and power calculations, along with buttons for input and operations. The code handles user input, performs calculations based on selected operations, and displays results in a text box.

Uploaded by

t7qnpvc6jd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Calculator

The document is a C# code for a simple calculator application using Windows Forms. It includes functionalities for basic arithmetic operations, square root, and power calculations, along with buttons for input and operations. The code handles user input, performs calculations based on selected operations, and displays results in a text box.

Uploaded by

t7qnpvc6jd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

using System;

using System.Windows.Forms;

namespace calculator
{
public partial class Form1 : Form
{
private string no1, constfun;
private bool inputstatus;

public Form1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)


{

private void button_Click(object sender, EventArgs e)


{
Button button = sender as Button;
if (inputstatus)
{
textBox1.Text += button.Text;
}
else
{
textBox1.Text = button.Text;
inputstatus = true;
}
}

private void buttonOperation_Click(object sender, EventArgs e)


{
Button button = sender as Button;
no1 = textBox1.Text;
textBox1.Text = "";
constfun = button.Text;
inputstatus = false;
}

private void buttonEqual_Click(object sender, EventArgs e)


{
double result;
double no2 = Convert.ToDouble(textBox1.Text);

switch (constfun)
{
case "+":
result = Convert.ToDouble(no1) + no2;
break;
case "-":
result = Convert.ToDouble(no1) - no2;
break;
case "*":
result = Convert.ToDouble(no1) * no2;
break;
case "/":
result = no2 == 0 ? double.PositiveInfinity : Convert.ToDouble(no1) / no2;
break;
case "%":
result = Convert.ToDouble(no1) % no2;
break;
case "√":
result = Math.Sqrt(no2);
break;
case "x^2":
result = Math.Pow(no2, 2);
break;
case "x^3":
result = Math.Pow(no2, 3);
break;
default:
result = 0;
break;
}

textBox1.Text = result.ToString();
inputstatus = false;
}

private void buttonClear_Click(object sender, EventArgs e)


{
textBox1.Text = "";
no1 = "";
constfun = "";
inputstatus = false;
}

private void buttonClearEntry_Click(object sender, EventArgs e)


{
textBox1.Text = "";
}

private void button12_Click(object sender, EventArgs e)


{
button_Click(sender, e);
}

private void button13_Click(object sender, EventArgs e)


{
button_Click(sender, e);
}

private void button14_Click(object sender, EventArgs e)


{
button_Click(sender, e);
}

private void button15_Click(object sender, EventArgs e)


{
button_Click(sender, e);
}

private void button16_Click(object sender, EventArgs e)


{
button_Click(sender, e);
}

private void button17_Click(object sender, EventArgs e)


{
button_Click(sender, e);
}

private void button18_Click(object sender, EventArgs e)


{
button_Click(sender, e);
}

private void button19_Click(object sender, EventArgs e)


{
button_Click(sender, e);
}

private void button20_Click(object sender, EventArgs e)


{
button_Click(sender, e);
}

private void button21_Click(object sender, EventArgs e)


{
button_Click(sender, e);
}

private void button7_Click(object sender, EventArgs e)


{
buttonOperation_Click(sender, e);
}

private void button8_Click(object sender, EventArgs e)


{
buttonOperation_Click(sender, e);
}

private void button9_Click(object sender, EventArgs e)


{
buttonOperation_Click(sender, e);
}

private void button10_Click(object sender, EventArgs e)


{
buttonOperation_Click(sender, e);
}

private void button11_Click(object sender, EventArgs e)


{
buttonEqual_Click(sender, e);
}

private void button3_Click(object sender, EventArgs e)


{
buttonClear_Click(sender, e);
}

private void button4_Click(object sender, EventArgs e)


{
buttonClearEntry_Click(sender, e);
}

private void button1_Click(object sender, EventArgs e)


{
constfun = "√";
buttonEqual_Click(sender, e);
}

private void button2_Click(object sender, EventArgs e)


{
buttonOperation_Click(sender, e);
}

private void button5_Click(object sender, EventArgs e)


{
constfun = "x^2";
buttonEqual_Click(sender, e);
}

private void button6_Click(object sender, EventArgs e)


{
constfun = "x^3";
buttonEqual_Click(sender, e);
}
}
}

You might also like