I have shown how you can perform math as well as logical operations together.
So first we will create a new windows application and design the below form.
Now use the below code,
- 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 Example_of_math_variables_and_if_statements
- {
- public partial class Form1 : Form
- {
- private string x;
- private string y;
- private string random_string;
- private int x_number;
- private int y_number;
- private int random;
- public Form1()
- {
- InitializeComponent();
- }
- private void radioButton1_CheckedChanged(object sender, EventArgs e)
- {
- x = this.textBox1.Text;
- y = this.textBox2.Text;
- if (x == "")
- {
- x = "0";
- }
- if (y == "")
- {
- y = "0";
- }
- x_number = Convert.ToInt32(x);
- y_number = Convert.ToInt32(y);
- random = x_number + y_number;
- random_string = Convert.ToString(random);
- this.label3.Text = random_string;
- }
- private void radioButton2_CheckedChanged(object sender, EventArgs e)
- {
- x = this.textBox1.Text;
- y = this.textBox2.Text;
- if (x == "")
- {
- x = "0";
- }
- if (y == "")
- {
- y = "0";
- }
- x_number = Convert.ToInt32(x);
- y_number = Convert.ToInt32(y);
- random = x_number - y_number;
- random_string = Convert.ToString(random);
- this.label3.Text = random_string;
- }
- private void radioButton4_CheckedChanged(object sender, EventArgs e)
- {
- x = this.textBox1.Text;
- y = this.textBox2.Text;
- if (x == "")
- {
- x = " 0";
- }
- if (y == "")
- {
- y = "0";
- }
- x_number = Convert.ToInt32(x);
- y_number = Convert.ToInt32(y);
- random = x_number * y_number;
- random_string = Convert.ToString(random);
- this.label3.Text = random_string;
- }
- private void radioButton3_CheckedChanged(object sender, EventArgs e)
- {
- x = this.textBox1.Text;
- y = this.textBox2.Text;
- if (x == "")
- {
- x = "0";
- }
- if (y == "")
- {
- y = "0";
- }
- x_number = Convert.ToInt32(x);
- y_number = Convert.ToInt32(y);
- if (y_number == 0)
- {
- random_string = "Divide by zero error";
- }
- else
- {
- random = x_number / y_number;
- random_string = Convert.ToString(random);
- }
- this.label3.Text = random_string;
- }
- private void radioButton7_CheckedChanged(object sender, EventArgs e)
- {
- x = this.textBox1.Text;
- y = this.textBox2.Text;
- if (x == "")
- {
- x = "0";
- }
- if (y == "")
- {
- y = "0";
- }
- x_number = Convert.ToInt32(x);
- y_number = Convert.ToInt32(y);
- if (x_number == y_number)
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
- }
- else
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
- }
- }
- private void radioButton8_CheckedChanged(object sender, EventArgs e)
- {
- x = this.textBox1.Text;
- y = this.textBox2.Text;
- if (x == "")
- {
- x = "0";
- }
- if (y == "")
- {
- y = "0";
- }
- x_number = Convert.ToInt32(x);
- y_number = Convert.ToInt32(y);
- if (x_number > y_number)
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
- }
- else
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
- }
- }
- private void radioButton6_CheckedChanged(object sender, EventArgs e)
- {
- x = this.textBox1.Text;
- y = this.textBox2.Text;
- if (x == "")
- {
- x = "0";
- }
- if (y == "")
- {
- y = "0";
- }
- x_number = Convert.ToInt32(x);
- y_number = Convert.ToInt32(y);
- if (x_number < y_number)
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
- }
- else
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
- }
- }
- private void radioButton5_CheckedChanged(object sender, EventArgs e)
- {
- x = this.textBox1.Text;
- y = this.textBox2.Text;
- if (x == "")
- {
- x = "0";
- }
- if (y == "")
- {
- y = "0";
- }
- x_number = Convert.ToInt32(x);
- y_number = Convert.ToInt32(y);
- if (x_number >= y_number)
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
- }
- else
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
- }
- }
- private void radioButton9_CheckedChanged(object sender, EventArgs e)
- {
- x = this.textBox1.Text;
- y = this.textBox2.Text;
- if (x == "")
- {
- x = "0";
- }
- if (y == "")
- {
- y = "0";
- }
- x_number = Convert.ToInt32(x);
- y_number = Convert.ToInt32(y);
- if (x_number <= y_number)
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
- }
- else
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
- }
- }
- private void radioButton10_CheckedChanged(object sender, EventArgs e)
- {
- x = this.textBox1.Text;
- y = this.textBox2.Text;
- if (x == "")
- {
- x = "0";
- }
- if (y == "")
- {
- y = "0";
- }
- x_number = Convert.ToInt32(x);
- y_number = Convert.ToInt32(y);
- if (x_number != y_number)
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
- }
- else
- {
- this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
- }
- }
- }
- }
In the above code I have performed all the math as well as logical operations.