Kodewick
Start learning →
Mini challenge←→0 / 60

Shelf label

#021Mini challengeStringsLoops6 min

On the reading-corner shelf labels, every word of a book title starts with a capital. Write title_case(title): words are separated by one space; make the first letter of each a capital and leave the rest alone. An empty title stays empty.

Examples
title_case("the little prince")→'The Little Prince'
title_case("")→''
The functionstring title_case(string title)
main.cpp
#include <string>
#include <cctype>
using namespace std;

string title_case(string title) {
    for (int i = 0; i < title.size(); i++) {
        // your code here: at the start or after a space, make title[i] a capital
    }
    return title;
}
Ctrl + Enter runs too
Result

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