Kodewick
Start learning →
Basic←→0 / 60

Kettle

#042BasicClasses4 min

The water in the kettle starts at 20 degrees. Each heat(deg) warms it by deg, but it never goes above 100: once it boils, it boils. Fill in heat.

Examples
kettle_temp({30, 25})→75
kettle_temp({})→20
The functionint kettle_temp(const vector<int> &heats)
main.cpp
#include <vector>
using namespace std;

class Kettle {
public:
    int temp;

    Kettle() {
        temp = 20;
    }

    void heat(int deg) {
        // your code here: heat it up, but not past 100
    }
};

int kettle_temp(const vector<int> &heats) {
    Kettle k;
    for (int d : heats) {
        k.heat(d);
    }
    return k.temp;
}
Ctrl + Enter runs too
Result

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