Kodewick
Start learning →
Starter→0 / 3

Add them up

#001StartervectorLoops3 min

Write sum_all(v) to add up every number in the vector and return it. An empty one gives 0.

Examples
sum_all({3, 4, 5})→12
sum_all({})→0
The functionint sum_all(const vector<int> &v)
main.cpp
#include <vector>
using namespace std;

int sum_all(const vector<int> &v) {
    int total = 0;
    // your code here: a range-for that adds each number to total
    return total;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.