Portfolio
Sum_Of_Positive
/*You get an array of numbers, return the sum of all of the positives ones.
Example [1,-4,7,12] => 1 + 7 + 12 = 20
Note: array may be empty, in this case return 0.
*/
#include <vector>
int positive_sum (const std::vector<int> arr){
int sum = 0;
std::vector<int>::const_iterator i;
for(i = arr.begin(); i != arr.end();i++)
if(*i > 0) sum += *i;
return sum;
}
