Multiple Control Structures
Ten
cannibals begin to eat thirty missionaries.
It takes an hour to consume the first missionary. At the end of each hour, if an entire
missionary has been consumed, one cannibal steals away
into the forest. Each of the remaining
cannibals continues to eat at the same rate.
However, as there are fewer consumers, fewer missionaries will be
consumed in each hour. Fortunately, for
the missionaries, help is on the way.
Tarzan is coming. However, he is
80 miles away. During the day, Tarzan
travels at 7 miles per hour. During the
darkness, he reduces his speed to 4 miles per hour. Darkness lasts nine hours. When the cannibals start eating there are
only three hours left to darkness. Write
a program to calculate and display how many cannibals will be caught and how
many missionaries saved. Display your
results in the following form:
END OF HOUR MISSIONARIES LEFT CANNIBALS EATING TARZAN DISTANCE
0 30 10 80
1 29 9 73
2 28.1 9 66
3
Items to
consider:
·
When
will the loop end? How many missionaries
can be saved?
·
Each
time through the loop is one hour (day or night?).
·
What
is the rate of consumption of one cannibal?
Consider
that a missionary partly consumed is NOT a missionary saved.