Kodewick
Start learning →
Basic←→0 / 60

Double letters

#020BasicStringsLoops4 min

For spelling cards, the kids need to know where the double letters are. Write doubled(word): count each letter that is the same as the one before it. coffee gives 2, aaa also gives 2, and an empty word gives 0.

Examples
doubled("coffee")→2
doubled("cat")→0
doubled("book")→1
The functionint doubled(const string &word)
main.cpp
#include <string>
using namespace std;

int doubled(const string &word) {
    int count = 0;
    for (int i = 1; i < word.size(); i++) {
        // your code here: if word[i] matches the one before, add 1 to count
    }
    return count;
}
Ctrl + Enter runs too
Result

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