- We are given the following:
- Two trains are traveling towards each other on the same track. One train is traveling at 30 miles per hour, the other at 20 mph. When the trains are 100 miles apart, a fly leaves one and flies towards the other. When it reaches the other it immediately travels back to the first. Upon returning, it immediately starts back to the second, and so on, until the trains crash.
-
- Question: When the trains crash, how far has the fly traveled, if it flies continuously at 50 mph?
-
- Note that when we say 'immediately' above, we mean that there was no time whatever lost in turning around -- that there was an instantaneous change of motion.
- Write a program that will take the distance of the trains from each other and the relative speeds of the trains and the fly as input and answer the question posed.