Numbers: -4, 4, 5, -2, -7, -5, 3, 3, -4, -3 |
Now how would we do this by hand. (Without regrouping the numbers.)
----------------------------------------------------------------------------------------
Let's take the first number.
Is the number positive or negative?
Negative.
So add it to our negative total (which starts at 0)
Our negative total is now -4
Let's take the next (second) number.
Is the number positive or negative?
Positive.
So add it to our positive total (which starts at 0)
Our positive total is now 4
Let's take the next (third) number.
Is the number positive or negative?
Positive.
So add it to our positive total (which is now at 4)
Our positive total is now 9
Etc...
----------------------------------------------------------------------------------------
So you need to try and write that algorithm in C++