How to create a basic calculator with c#

Channel:
Subscribers:
449
Published on ● Video Link: https://www.youtube.com/watch?v=7Z6dKTmYRoI



Category:
Tutorial
Duration: 25:59
360 views
3


//SOURCE CODE for Form1.cs
using System;
using System.Windows.Forms;

namespace WindowsFormsTutorial
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}



private void buttonCalculate_Click(object sender, EventArgs e)
{
decimal value1=0;
decimal value2=0;
decimal result = 0;
textBox3.Text = "";
if (decimal.TryParse(textBox1.Text, out value1) == false)
{
MessageBox.Show("Error! Failed to parse! Please do not insert stupid crap.","ERROR");
}
else if (decimal.TryParse(textBox2.Text, out value2) == false)
{
MessageBox.Show("Error! Failed to parse! Please do not insert stupid crap.", "ERROR");
}
else if(radioAdd.Checked==true)
{
result = value1 + value2;
}
else if (radioDivide.Checked == true)
{
if (value2 != 0)
{
result = value1 / value2;
}
else { textBox3.Text = "Undefined - divide by "; }



}
else if (radioMultiply.Checked == true)
{
result = value1 * value2;
}
else if (radioSubtract.Checked == true)
{
result = value1 - value2;
}
else if (radioMod.Checked == true)
{
result = value1 % value2;
}
textBox3.Text += result;

}
}
}







Tags:
C# (Programming Language)
How-to (Website Category)
Visual Studio
Microsoft Windows (Operating System)
Windows Application
Application
programming
Programming Language (Software Genre)
Tutorial
Computer