This is how to do basic Math

There are plenty of different types of Math you can do in a program but we will just go over the four basic ones: Adding, Subtracting, Division and Multiplication.

We will start out with Adding and Subtracting:

To do this, add the following lines of code to a console program:

Int32 x = 4;

Int32 y = 2;

Int32 adding;

adding = x + y;

Console.WriteLine(String.Concat(x.ToString(), "+", y.ToString(), "=", adding.ToString()));

Int32 subtracting;

subtracting = x - y;

Console.WriteLine(String.Concat(x.ToString(), "-", y.ToString(), "=", subtracting.ToString()));

Console.ReadKey();

This is how to Multiply and Divide:

Double x = 4.25;

Double y = 5;

Double multiplying; multiplying = x * y;

Console.WriteLine(String.Concat(x.ToString(), "*", y.ToString(), "=", multiplying.ToString()));

Double dividing;

dividing = x / y;

Console.WriteLine(String.Concat(x.ToString(), "/", y.ToString(), "=", dividing.ToString()));

Console.ReadKey();

  • Remember to mulptiply to use the * and to divide use /
  • Now that you know how to do these, try making a calculator!