Kodewick
Start learning →
Basic←→0 / 86

The Piggy Bank

#079Basicwhile (saved < goal)4 min

The piggy bank starts empty and gets 15 every week, until it holds 100. Show how many weeks that takes. The saving line is written — only the week count is missing.

Should show
7
main.cpp
#include <iostream>
using namespace std;

int main() {
    int saved = 0;
    int weeks = 0;
    while (saved < 100) {
        saved += 15;
        // your code here: add one to the number of weeks
    }
    cout << weeks << endl;
    return 0;
}
Ctrl + Enter runs too
Result

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