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.
coin_run("ccg")→7coin_run("")→0int coin_run(const string &path)#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;
}
Run tries the examples. When they look right, Submit.