Addition is defined by anal mathematicians as "a mathematical operation by which one value is increased by the value of another." Well — duh.
I can understand how this definition might be useful when trying to explain addition to a very small, and most likely, stupid child. However, it boggles my mind why such supposedly smart mathematicians would go around talking about addition in such a redundant way to each other.
In school, you probably learned two general ways for your numbers to get it on. Missionary and Aerobatic Doggie Style. Here's an example of each :
Missionary
2 + 2 = 4
Aerobatic Doggie Style
2
+ 2
---
4
Numbers (and all math for that matter) when used in programming are prudish bores, not like their free-lovin' on-paper cousins. There is no Acrobatic Doggie Style for them, no siree. They only do it missionary. However, they have one important kink — they do it backwards. Here's what it would look like on paper :
4 = 2 + 2
Also in programming, you don't actually see the 4. It's the result of the math and you have to do something with it usually one of these four:
#. Display it.
#. Store it.
#. Compare it to something.
#. Use it in some other math.
Right now we'll just display it, you'll learn the hows and whys of the other three later.
Here's an example of simply displaying it, you will use this to solve the problems below :
SetFPS 60
Do
Cls 0
Print 2 + 2
Sync
Loop
Addition Problems
1. The player has accumulated a score of 230. He picks up a coin worth 10 points. What is the score after the player picks up the coin?
2. The player has 1300 experience points. He kills a monster worth 30 experience points. How many experience points does the player have?
3. The player's game object moves two pixels per frame and is located at pixel 532. Assuming he is moving right (requiring addition), where will it be at the start of the next frame?
The answers are available on the Addition Answers page.
Preserved Text From GDN
Addition is mathematical operation that increases the value of a number by another.
Addition in Programming
Addition pretty much looks the same in almost all programming languages. Two numbers, or variables are added together using the addition operator ( + ).
5 + 5
This expression results in 10, however, you need need to do something with the result of the addition. You can either put it into a variable, or PRINT it.
dim sum as integer
sum = 5 + 5
'or
print 5 + 5
sleep
end
Properties of Addition
What follows is very anal math geek stuff.
Commutative Property of Addition
The commutative property of addition says that you can add numbers in any order and come up with the same result. It doesn't matter if you add 3 + 5 or 5 + 3, both equal 8.
Associative Property of Addition
The associative properly to addition says that no matter how you group numbers to add them together, you will come up with the same result. For example (3 + 5) + 1 will add up to the same result as (5 + 1) + 3.
Identity Property of Addition
The identity property of addition states that any number added to 0 results in the very same number. Amazing! So, if you add 5 + 0, nothing changes and you wind up with 5 and a few seconds of your life wasted.
Binary Addition
Binary addition works exactly like addition in base 10. Here's an example of adding 100001 (33) to 10101 (21) :
100001
10101
------
110110
To Do
- The two "branches of text" needs to be combined.