namespace Calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
if ((textBox1.Text == string.Empty)||(textBox2.Text==string.Empty))
{
MessageBox.Show("Please enter some numbers to validate");
}
else
{
int Total = Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text);
textBox3.Text = Convert.ToString(Total);
}
}
catch (Exception ex)
{
MessageBox.Show("Number1 and Number2 should be numeric");
}
}
private void btnSubtract_Click(object sender, EventArgs e)
{
try
{
if ((textBox1.Text == string.Empty) || (textBox2.Text == string.Empty))
{
MessageBox.Show("Please enter some numbers to validate");
}
else
{
if (Convert.ToInt32(textBox1.Text) > Convert.ToInt32(textBox2.Text))
{
int Total = Convert.ToInt32(textBox1.Text) - Convert.ToInt32(textBox2.Text);
textBox3.Text = Convert.ToString(Total);
}
else
{
MessageBox.Show("Number1 should be greater than Number2");
}
}
}
catch (Exception ex)
{
MessageBox.Show("Number1 and Number2 should be numeric");
}
}
private void btnMultiply_Click(object sender, EventArgs e)
{
try
{
if ((textBox1.Text == string.Empty) || (textBox2.Text == string.Empty))
{
MessageBox.Show("Please enter some numbers to validate");
}
else
{
int Total = Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox2.Text);
textBox3.Text = Convert.ToString(Total);
}
}
catch(Exception ex)
{
MessageBox.Show("Number1 and Number2 should be numeric");
}
}
private void btnDivide_Click(object sender, EventArgs e)
{
try
{
if ((textBox1.Text == string.Empty) || (textBox2.Text == string.Empty))
{
MessageBox.Show("Please enter some numbers to validate");
}
else
{
if (Convert.ToInt32(textBox1.Text) > Convert.ToInt32(textBox2.Text))
{
int Total = Convert.ToInt32(textBox1.Text) / Convert.ToInt32(textBox2.Text);
textBox3.Text = Convert.ToString(Total);
}
else
{
MessageBox.Show("Number1 should be greater than Number2");
}
}
}
catch (Exception ex)
{
MessageBox.Show("Number1 and Number2 should be numeric");
}
}
}
}
Output:
16 years ago
No comments:
Post a Comment