Kodewick
Start learning →
Starter←→0 / 70

Birthday candles

#024StarterLoops3 min

On each birthday cake there is one candle per year of age. Write total_candles(age) to work out how many candles were used from age 1 to age. An age of 0 is 0 candles.

Examples
total_candles(3)→6
total_candles(1)→1
The functionint total_candles(int age)
main.c
int total_candles(int age) {
    int total = 0;
    for (int year = 1; year <= age; year++) {
        // your code here: add this year's candles to total
    }
    return total;
}
Ctrl + Enter runs too
Result

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