Kodewick
Start learning →
Mini challenge←→0 / 60

Coin run

#059Mini challengeStringsLoops6 min

In a running game, path is what you hit along the way: 'c' a coin, +1; 'g' a gem, +5; 'x' an obstacle, -3, but the score never goes below 0. Any other character scores nothing. Fill in the loop.

Examples
coin_run("ccg")→7
coin_run("")→0
The functionint coin_run(const string &path)
main.cpp
#include <string>
using namespace std;

int coin_run(const string &path) {
    int score = 0;
    for (char ch : path) {
        // your code here: add or take points for ch
    }
    return score;
}
Ctrl + Enter runs too
Result

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