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,

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace Example_of_math_variables_and_if_statements
  11. {
  12. public partial class Form1 : Form
  13. {
  14. private string x; //This defines the string variable x
  15. private string y;
  16. private string random_string;
  17. private int x_number; //This defines the integer variable x_number
  18. private int y_number;
  19. private int random;
  20. public Form1()
  21. {
  22. InitializeComponent(); //This creates the window from the information that was entered in the form designer
  23. }
  24. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  25. {
  26. x = this.textBox1.Text;
  27. y = this.textBox2.Text;
  28. if (x == "") //This sees if x has no value
  29. {
  30. x = "0"; //This sets x to 0
  31. }
  32. if (y == "") //This sees if x has no value
  33. {
  34. y = "0"; //This sets y to 0
  35. }
  36. x_number = Convert.ToInt32(x); //This converts the string x to a integer then stores it in x_number
  37. y_number = Convert.ToInt32(y);
  38. random = x_number + y_number; //This sets the integer variable random to the value of x_number plus y_number
  39. random_string = Convert.ToString(random); //This converts the integer random to the string random_string
  40. this.label3.Text = random_string;
  41. } //This method is called when the radiobutton (a button that when pressed makes every other radiobutton in its groupbox not pressed) is changed
  42. private void radioButton2_CheckedChanged(object sender, EventArgs e)
  43. {
  44. x = this.textBox1.Text;
  45. y = this.textBox2.Text;
  46. if (x == "")
  47. {
  48. x = "0";
  49. }
  50. if (y == "")
  51. {
  52. y = "0";
  53. }
  54. x_number = Convert.ToInt32(x);
  55. y_number = Convert.ToInt32(y);
  56. random = x_number - y_number;
  57. random_string = Convert.ToString(random);
  58. this.label3.Text = random_string;
  59. }
  60. private void radioButton4_CheckedChanged(object sender, EventArgs e)
  61. {
  62. x = this.textBox1.Text;
  63. y = this.textBox2.Text;
  64. if (x == "")
  65. {
  66. x = " 0";
  67. }
  68. if (y == "")
  69. {
  70. y = "0";
  71. }
  72. x_number = Convert.ToInt32(x);
  73. y_number = Convert.ToInt32(y);
  74. random = x_number * y_number;
  75. random_string = Convert.ToString(random);
  76. this.label3.Text = random_string;
  77. }
  78. private void radioButton3_CheckedChanged(object sender, EventArgs e)
  79. {
  80. x = this.textBox1.Text;
  81. y = this.textBox2.Text;
  82. if (x == "")
  83. {
  84. x = "0";
  85. }
  86. if (y == "")
  87. {
  88. y = "0";
  89. }
  90. x_number = Convert.ToInt32(x);
  91. y_number = Convert.ToInt32(y);
  92. if (y_number == 0) //This is to make sure that we don't divide by 0
  93. {
  94. random_string = "Divide by zero error";
  95. }
  96. else
  97. {
  98. random = x_number / y_number;
  99. random_string = Convert.ToString(random);
  100. }
  101. this.label3.Text = random_string;
  102. }
  103. private void radioButton7_CheckedChanged(object sender, EventArgs e)
  104. {
  105. x = this.textBox1.Text;
  106. y = this.textBox2.Text;
  107. if (x == "")
  108. {
  109. x = "0";
  110. }
  111. if (y == "")
  112. {
  113. y = "0";
  114. }
  115. x_number = Convert.ToInt32(x);
  116. y_number = Convert.ToInt32(y);
  117. if (x_number == y_number) //This checks if the integer x_number is equal to the integer y_number
  118. {
  119. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes; //If it is the picture is set to a check
  120. }
  121. else //If they are not then the picture is set as an X
  122. {
  123. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
  124. }
  125. }
  126. private void radioButton8_CheckedChanged(object sender, EventArgs e)
  127. {
  128. x = this.textBox1.Text;
  129. y = this.textBox2.Text;
  130. if (x == "")
  131. {
  132. x = "0";
  133. }
  134. if (y == "")
  135. {
  136. y = "0";
  137. }
  138. x_number = Convert.ToInt32(x);
  139. y_number = Convert.ToInt32(y);
  140. if (x_number > y_number) //Check if the integer x_number is greater than integer y_number
  141. {
  142. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
  143. }
  144. else
  145. {
  146. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
  147. }
  148. }
  149. private void radioButton6_CheckedChanged(object sender, EventArgs e)
  150. {
  151. x = this.textBox1.Text;
  152. y = this.textBox2.Text;
  153. if (x == "")
  154. {
  155. x = "0";
  156. }
  157. if (y == "")
  158. {
  159. y = "0";
  160. }
  161. x_number = Convert.ToInt32(x);
  162. y_number = Convert.ToInt32(y);
  163. if (x_number < y_number) //Check if the integer x_number is less than integer y_number
  164. {
  165. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
  166. }
  167. else
  168. {
  169. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
  170. }
  171. }
  172. private void radioButton5_CheckedChanged(object sender, EventArgs e)
  173. {
  174. x = this.textBox1.Text;
  175. y = this.textBox2.Text;
  176. if (x == "")
  177. {
  178. x = "0";
  179. }
  180. if (y == "")
  181. {
  182. y = "0";
  183. }
  184. x_number = Convert.ToInt32(x);
  185. y_number = Convert.ToInt32(y);
  186. if (x_number >= y_number) //Check if the integer x_number is greater than or equal to integer y_number
  187. {
  188. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
  189. }
  190. else
  191. {
  192. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
  193. }
  194. }
  195. private void radioButton9_CheckedChanged(object sender, EventArgs e)
  196. {
  197. x = this.textBox1.Text;
  198. y = this.textBox2.Text;
  199. if (x == "")
  200. {
  201. x = "0";
  202. }
  203. if (y == "")
  204. {
  205. y = "0";
  206. }
  207. x_number = Convert.ToInt32(x);
  208. y_number = Convert.ToInt32(y);
  209. if (x_number <= y_number) //Check if the integer x_number is less than or equal to integer y_number
  210. {
  211. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
  212. }
  213. else
  214. {
  215. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
  216. }
  217. }
  218. private void radioButton10_CheckedChanged(object sender, EventArgs e)
  219. {
  220. x = this.textBox1.Text;
  221. y = this.textBox2.Text;
  222. if (x == "")
  223. {
  224. x = "0";
  225. }
  226. if (y == "")
  227. {
  228. y = "0";
  229. }
  230. x_number = Convert.ToInt32(x);
  231. y_number = Convert.ToInt32(y);
  232. if (x_number != y_number) //Check if the integer x_number is not equal to integer y_number
  233. {
  234. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.yes;
  235. }
  236. else
  237. {
  238. this.pictureBox1.Image = global::Example_of_math_variables_and_if_statements.Properties.Resources.no;
  239. }
  240. }
  241. }
  242. }
In the above code I have performed all the math as well as logical operations.