# Arithmetic functions

There are a number of arithmetic functions that can performed on integers. Some of the basic functions are as follows:

 Operator Function + add - subtract * multiple / divide

To use these functions, the following format needs to be used:

integer <function> integer

The following examples can be entered into Seed console to show them in action. The instructions to enter Seed console are here.

```print (4/2);
print (2+2);
print (10*10);
print (9-2);```

These functions can be used with variables containing integers. The following examples can be run in Console:

```var number1 = 5, number2 = 10;
print (number1 - number2);
print (number1 & number2);```

For most occasions, when using integer variables, you will performing arithmetic functions on variables that will change it's original value. An example of this is you were keeping a tally, you would create a variable and then for each instance of something happening you would increase the variables value by 1.

The format to do this is as follows:

<variable> = <variable> function integer

If you were using another variable, it would be:

<variable> = <variable> function <other variable>

Examples of these are as follows:

```number1 = number1 + 5;
number2 = number2 * number1;
number2 = number1 * 20;```

There is another way of doing this by using assignment operators. There are a number of assignment operators but the basic ones are as follows:

 Operator Description Example Long version += Add to variable x += 1 x = x + 1 -= Subtract from variable x -=1 x = x -1 *= Multiple to variable x *=2 x = x * 2 /= Divide by variable x /=3 x = x / 3 -- Subtract 1 from variable x-- or --x x = x -1 ++ add 1 to variable x++ or ++x x = x +1

Examples of these are as follows which can be entered into the console to see the results:

```var number = 10;
number +=1; ; print (number);
number++; print (number);
number -=3; print (number);
number-- ; print (number);
number *=4; print (number);
--number ; print (number);
++number; print (number);```

You will notice the last two operators in the table and the examples that the operators ++ and -- can be used before and after the variable. What is the difference? When using on variables on their own nothing but when used in conjunction with other variables, they behave differently.

If ++ or -- operator is used after the variable, it returns it's present value for calculation before either increasing or decreasing by 1. If used before the variable, it increases or decreases the variables value and then returns it to calculation. The following example shows this:

```var x = 10;
var y = x++;
print ("x =" + x + " y =" + y);```

This returns:

```x = 11
y = 10```

But with

```var x = 10;
var y = ++x;
print ("x =" + x + " y =" + y);```

Returns this:

```x = 11
y = 11 ```

Projects/Seed/Tutorial/basic/arithmetic (last edited 2013-11-22 19:19:56 by WilliamJonMcCann)