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.
doubled("coffee")→2doubled("cat")→0doubled("book")→1int doubled(const string &word)#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;
}
Run tries the examples. When they look right, Submit.