Kodewick
Start learning →
Basic←→0 / 70

Practice stars

#063BasicArraysConditions5 min

A piano practice app scores each song: 90 or more earns 3 stars, 70 or more 2, 50 or more 1, below that none. Write stars_earned(scores, n) for the total stars over n songs. No songs gives 0.

Examples
stars_earned({95, 72, 40}, 3)→5
stars_earned({50}, 1)→1
The functionint stars_earned(int scores[], int n)
main.c
int stars_earned(int scores[], int n) {
    int stars = 0;
    for (int i = 0; i < n; i++) {
        // your code here: by this score, add 3, 2, 1 or nothing to stars
    }
    return stars;
}
Ctrl + Enter runs too
Result

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