0% found this document useful (0 votes)
4 views3 pages

Calculator R

The document is a C# Windows Forms application for a basic calculator. It includes functionalities for arithmetic operations, special operations like square root and exponentiation, and input handling. The application maintains the state of inputs and operations through various event handlers for button clicks.

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)
4 views3 pages

Calculator R

The document is a C# Windows Forms application for a basic calculator. It includes functionalities for arithmetic operations, special operations like square root and exponentiation, and input handling. The application maintains the state of inputs and operations through various event handlers for button clicks.

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/ 3

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 CALC_FINAL
{
public partial class Form1 : Form
{
private string no1, constfun;
private bool inputstatus;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private void buttonclick(object sender, EventArgs e)


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

private void specialoperation(object sender, EventArgs e)


{
Button button = sender as Button;
double value = Convert.ToDouble(textbox.Text);
double result;

switch (button.Name)
{
case "sqrt":
result = Math.Sqrt(value);
break;
case "square":
result = Math.Pow(value, 2);
break;
case "cube":
result = Math.Pow(value, 3);
break;
default:
result = 0;
break;
}

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

private void equals_Click(object sender, EventArgs e)


{
double result;
double no2 = Convert.ToDouble(textbox.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;
default:
result = 0;
break;
}
textbox.Text = result.ToString();
inputstatus = false;
}

private void clear_Click(object sender, EventArgs e)


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

private void clearentry_Click(object sender, EventArgs e)


{
textbox.Text = "";
}

private void operationclick(object sender, EventArgs e)


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

You might also like