0% found this document useful (0 votes)
73 views4 pages

C# Basic Arithmetic Calculator Code

The document describes a C# calculator program that allows a user to select an arithmetic operation, enter two values, and then displays the result of calculating those values using the selected operation. The program uses variables to store the operation, values, and results and uses if/else statements to check the operation and perform the appropriate calculation on the values. The operations included are addition, subtraction, multiplication, and division.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views4 pages

C# Basic Arithmetic Calculator Code

The document describes a C# calculator program that allows a user to select an arithmetic operation, enter two values, and then displays the result of calculating those values using the selected operation. The program uses variables to store the operation, values, and results and uses if/else statements to check the operation and perform the appropriate calculation on the values. The operations included are addition, subtraction, multiplication, and division.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

C# Calculator

using System;

public class Program


{
public static void Main()
{

char Operation;
double SUM, DIFF, PROD, QUOT, first_Value, second_Value;

[Link]("Arithmetic Operation");
[Link]("\t[A] for \"Addition\"");
[Link]("\t[S] for \"Subtraction\"");
[Link]("\t[M] for \"Multiplication\"");
[Link]("\t[D] for \"Division\"");

[Link]("Select the Arithmetic Operation: ");


Operation = [Link]([Link]());

if (Operation != 'A' && Operation != 'a' && Operation != 'S' && Operation != 's' && Operation
!= 'M' && Operation != 'm' && Operation != 'D' && Operation != 'd')
{
[Link]("That Operation is not part of the choices");
}

else
[Link]("Enter the First Value: ");
first_Value = [Link]([Link]());
[Link]("Enter the Second Value: ");
second_Value = [Link]([Link]());

if (Operation == 'A' || Operation == 'a')


{
SUM = first_Value + second_Value;
[Link]("The Sum of the two value is: " + SUM);
}
else if (Operation == 'S' || Operation == 's')
{
DIFF = first_Value - second_Value;
[Link]("The Difference of the two value is: " + DIFF); }
else if (Operation == 'M' || Operation == 'm')
{
PROD = first_Value * second_Value;
[Link]("The Product of the two value is: " + PROD); }
else if (Operation == 'D' || Operation == 'd')
{
QUOT = first_Value / second_Value;
[Link]("The Quotient of the two value is: " + QUOT); }

[Link]();
}
}
Output
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

namespace Calculator
{
public partial class Form1 : Form
{
Double value = 0;
String operation = "";
bool operation_pressed = false;

public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button_Click(object sender, EventArgs e)
{
if (([Link] == "0")||(operation_pressed))
[Link]();
Button b = (Button)sender;
[Link] = [Link] + [Link];
}
private void button16_Click(object sender, EventArgs e)
{
[Link] = "0";
}
private void operator_click(object sender, EventArgs e)
{
Button b = (Button)sender;
operation = [Link];
value = [Link]([Link]);
operation_pressed = true;
}
private void button18_Click(object sender, EventArgs e)
{
switch (operation)
{
case "+":
[Link] = (value + [Link]([Link])).ToString();
break;
case "-":
[Link] = (value - [Link]([Link])).ToString();
break;
case "*":
[Link] = (value * [Link]([Link])).ToString();
break;
case "/":
[Link] = (value / [Link]([Link])).ToString();
break;
default:
break;
}//endswitch
operation_pressed = false; }
}
}
Output

You might also like