Kodewick
Start learning →
Basic←→0 / 70

Weather diary

#064BasicStringsConditions4 min

The weather diary has one letter a day in week: S sunny, R rainy, C cloudy. Count how many days of each; the line that prints them is already written.

Should show
Sunny 3, rainy 3, cloudy 1
main.c
#include <stdio.h>

int main(void) {
    char week[] = "SRCSRRS";
    int sunny = 0, rainy = 0, cloudy = 0;
    for (int i = 0; week[i] != '\0'; i++) {
        // your code here: by the letter, add 1 to sunny, rainy or cloudy
    }
    printf("Sunny %d, rainy %d, cloudy %d\n", sunny, rainy, cloudy);
    return 0;
}
Ctrl + Enter runs too
Result

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