Can someone explain please?

I'm wondering what loop to use and whatnot to complete the assignment because I don't have the slightest clue.


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.



I don't want the answer, just examples and explanation so I can understand. So please someone help me.
Last edited on
Starting conditions:
- TarzanDistance=80 (int)
- NumberCannibals=10 (int)
- NumberMissionaries=30 (double)
- EatingRate=0.1 (double)
- Time=0 (int)
- NightStarts=3 (int)
- NightEnds=12 (int)
- NightSpeed=4 (int)
- DaySpeed=7 (int)
You would use a do...while loop, to update the variables, and exit when TarzanDistance<=0
Inside the loop, you need to do:
- Time++; Time=Time%24; (just to make sure you are less then 24 hours)
- NumberMissionaries=NumberMissionaries-NumberCannibals*EatingRate
- Check if NumberMissionaries==floor(NumberMissionaries). That means that a full missionary was consumed. If true, NumberCannibals--
- Update TarzanDistance. If Time>NightStarts and Time<=NightEnds, TarzanDistance=TarzanDistance-NightSpeed, else TarzanDistance=TarzanDistance-DaySpeed
I feel so dumb, what was your thought process?
There are two problems that you solve in parallel:
1. when does Tarzan arrive? For this you need to calculate after every hour how far it is. And that depends on the time of the day, because his velocity changes
2. how many missionaries remain? The rate that they get eaten depends on how many cannibals are left
The rest is just putting into equations/ computer statements what is in the text
- Check if NumberMissionaries==floor(NumberMissionaries). That means that a full missionary was consumed. If true, NumberCannibals--

doesn't seem to work
Topic archived. No new replies allowed.