I would like to know how to code division addition and subtraction. I learned how to code multiplication from tutorial 4 or 5 I cannot remember which please help im just currious. :D
Printable View
I would like to know how to code division addition and subtraction. I learned how to code multiplication from tutorial 4 or 5 I cannot remember which please help im just currious. :D
Note that your "unknown" goes on the left hand side.Code:X = A + B;
X = A - B;
X = A * B;
X = A / B;
The equal sign is the assignment operator. You are assigning the value on the right to the variable on the left.
[EDIT -
And, be careful when dividing integers 1 / 2 won't give the right answer, because the result will be a truncated integer. 1.0 / 2.0 will result in a floating point answer.
The colored text is past the // symbols and therefor a comment, and not part of the code, just text to explain the line.Code:int number1 = 5;
int number2 = 10;
int number3;
number3 = 1 + 1; // = 2
number3 = number1 + number2; // = 5 + 10 = 15
number3 = number2 / number1; // = 10 divided by ( / ) 5 = 2
number3 = number2 - number1; // = 10 - 5 = 5
number3 = number3 * 2; // = the previously stored number ( 5 ) x 2 = 10
number3 = number3 + 5; // = the previously stored number ( 10 ) + 5 = 15;
number3 += 5; // = the previously stored number ( 15 ) + 5 = 20 ( number3 += is just like saying number3 = number3 +
thanks a bunch! I will give those a shot thx.