C SHARP CALCULATOR: C# (pronounced as seeing C SHARP) is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines. Below is the coding for a calculator on c-sharp easy to learn…
C SHARP CALCULATOR CODING
Before you start this Coding there is the basis of what you should do…
PC or Tablet depending on your choice
You should have a Virtual studio
Power supply if your battery doesn’t last long enough
JDK installed on your device
Proceed as follow…
On the PC Background, double-click on the App icon to Launch App
Select C Sharp
Click on Windows Application
Name your App and click Save.
C Sharp Calculator coding Interface displays and enter the codes as follows…
Name your Labels and txt as…
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Linq;
using System.Text; using System.Windows.Forms;
// All should be in straight line and close accordindly
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string input = string.Empty;
string operand1 = string.Empty;
string operand2 = string.Empty;
char operation;
double result = 0.0;
public Form1()
{
InitializeComponent();
}
private void one_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “1”;
this.tb.Text += input;
}
private void two_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “2”;
this.tb.Text += input;
}
private void three_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “3”;
this.tb.Text += input;
}
private void four_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “4”;
this.tb.Text += input;
}
private void five_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “5”;
this.tb.Text += input;
}
private void six_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “6”;
this.tb.Text += input;
}
private void seven_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “7”;
this.tb.Text += input;
}
private void eight_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “8”;
this.tb.Text += input;
}
private void nine_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “9”;
this.tb.Text += input;
}
private void zero_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “0”;
this.tb.Text += input;
}
private void dot_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
input += “.”;
this.tb.Text += input;
}
private void plus_Click(object sender, EventArgs e)
{
operand1 = input;
operation = ‘+’;
input = string.Empty;
}
private void minus_Click(object sender, EventArgs e)
{
operand1 = input;
operation = ‘-‘;
input = string.Empty;
}
private void divide_Click(object sender, EventArgs e)
{
operand1 = input;
operation = ‘/’;
input = string.Empty;
}
private void star_Click(object sender, EventArgs e)
{
operand1 = input;
operation = ‘*’;
input = string.Empty;
}
private void clr_Click(object sender, EventArgs e)
{
this.tb.Text = “”;
this.input = string.Empty;
this.operand1 = string.Empty;
this.operand2 = string.Empty;
}
private void equal_Click(object sender, EventArgs e)
{
operand2 = input;
double num1, num2;
double.TryParse(operand1, out num1);
double.TryParse(operand2, out num2);
this.tb.Text = “”;
this.input = string.Empty;
this.operand1 = string.Empty;
this.operand2 = string.Empty;
if (operation == ‘+’)
{
result = num1 + num2;
tb.Text = result.ToString(“N”);
}
else if (operation == ‘-‘)
{
result = num1 – num2;
tb.Text = result.ToString(“N”);
}
else if (operation == ‘*’)
{
result = num1 * num2;
tb.Text = result.ToString(“N”);
}
else if (operation == ‘/’)
{
if (num2 != 0)
{
result = num1 / num2;
tb.Text = result.ToString(“N”);
}
else
{
tb.Text = “DIV/Zero!”;
}
}
}
}
}
Meanwhile, You can Join our email subscribers for your daily notification, on our daily articles all are free, just using any email address only and if you don’t have a good working email address just make your choice …
Downloads | IDE, Code, & Team Foundation Server | Visual Studio
Get your free email registration now
Google account review
Yahoo mail review
Microsoft account review
Yandex registration
QQ Mail Id registration
Do you have any corrections to make use the comment box below