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.
This is a discussion on function question within the C++ Programming forums, part of the General Programming Boards category; I would like to know how to code division addition and subtraction. I learned how to code multiplication from tutorial ...
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.
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.
Last edited by DougDbug; 08-31-2005 at 03:52 PM.
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 +
Last edited by Dae; 08-31-2005 at 03:50 PM.
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101
thanks a bunch! I will give those a shot thx.