A loaf needs 400 g of flour, and flour_for(loaves) already works out the grams. Write bags_needed(loaves): flour comes in 1000 g bags, so how many bags to buy (a part bag still means a whole bag)? You only call flour_for to get the grams; the rest is written.
bags_needed(5)→2bags_needed(1)→1int bags_needed(int loaves)int flour_for(int loaves) {
return loaves * 400;
}
int bags_needed(int loaves) {
int grams = 0;
// your code here: call flour_for and put the grams in grams
int bags = grams / 1000;
if (grams % 1000 != 0) {
bags++;
}
return bags;
}
Run tries the examples. When they look right, Submit.