Fill a bottle by iteration
The previous exercise asked you to choose a model. Use the specified values and rules below for this exercise.
Scenario. A 750-milliliter bottle is filled using a 200-milliliter cup. Each round fills the cup, pours only the amount still needed into the bottle, and counts that cupful. Any water left in the final cup remains in the cup.
Inputs. bottle_capacity = 750 mL and cup_capacity = 200 mL.
Rules and notation. Start with bottle_volume = 0 and cupfuls = 0. In each round, pour minimum(cup_capacity, bottle_capacity - bottle_volume) milliliters and then increase cupfuls by 1. Here, minimum(a, b) means the smaller of a and b.
Assumptions. Capacities are positive whole numbers. No water leaks from the bottle. A partly used final cup still counts as one cupful.
Deliverable. Write pseudocode with a stopping condition. State the final values of bottle_volume and cupfuls, and how much water remains in the final cup. The solution includes a round-by-round trace. ?@sec-tracing-testing-improving uses the same problem to show why the choice of test inputs matters.
Success criteria. The algorithm is designed to stop with exactly 750 mL in the bottle, never overfill it, and count every cupful it uses, including a partly used final cup.
The final round is different: the bottle may need less than a full cup.