Kodewick
Start learning →
Basic←→0 / 60

Bread price rise

#036BasicReferencesLoops4 min

Every loaf at the bakery is going up by extra. Write raise_all(prices, extra): use a range-for to add extra to each price in prices. No bread (empty) means nothing changes.

Examples
new_prices({10, 12, 8}, 2)→[12, 14, 10]
new_prices({}, 5)→[]
The functionvector<int> new_prices(vector<int> prices, int extra)
main.cpp
#include <vector>
using namespace std;

void raise_all(vector<int> &prices, int extra) {
    // your code here: add extra to every price
}

vector<int> new_prices(vector<int> prices, int extra) {
    raise_all(prices, extra);
    return prices;
}
Ctrl + Enter runs too
Result

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