An employee charged with topping up an oil reservoir is given the following inst
ID: 3837140 • Letter: A
Question
An employee charged with topping up an oil reservoir is given the following instructions:
while the reservoir contains less than 20 litres do
if the reservoir contains less than 16 litres then
add a 5 litre can of oil to the reservoir
else
add a 1 litre can of oil to the reservoir
endif
endwhile
a) How much oil will the reservoir wind up containing if it initially contains 14.5 litres of oil?
b) How much oil will the reservoir wind up containing if it initially contains 20.1 litres of oil?
Explanation / Answer
(a) initially contains 14.5 litres of oil
While condition True
else --> 15.5
else --> 16.5
if --> 21.5
end while loop
reservoir wind up containing : 21.5 Liters
(b) initially contains 20.1 litres of oil
while loop condition False : end while loop
reservoir wind up containing : 20.1 Liters
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.