I'm having trouble writing the correct loops for an assignment. I have all the Math and Functions written; I'm just having a hard time understanding how to write the loops in order to calculate and show the correct output. Essentially, this is what I need to do:
A small test rocket is being designed for use in testing a retrorocket that is intended to permit “soft” landings. The designers have derived the following equations that they believe will predict the performance of the test rocket.
Note: The distance equation gives the height above ground level at time t and the first term (90) is the height in feet above ground level of the launch platform that will be used.
In order to check the predicted performance, the rocket will be “flown” on a computer, using the derived equations.
Write a program to cover a maximum flight of 100 seconds. The output should be of the following form:
TIME ACCELERATION VELOCITY DISTANCE
(sec) (ft/sec2) (ft/sec) (ft)
XXX.XX XXX.XX XXX.XX XXXX.XX
(starting with 0.0 sec)
Increments of time are to be 2.0 seconds, from launch through the ascending and descending portions of the trajectory until the rocket descends to within 60 feet of ground level. Below 60 feet the time increments are to be 0.05 seconds. If the rocket impacts prior to 100 seconds, the program is to be stopped immediately after impact.
That I can fix. The trouble I'm having is with how to write the loops so that they calculate at an increment of 2.0 seconds from launch through the ascending and descending portions. When the Rocket gets to 60 feet the increment goes from 2.0 down to 0.05 seconds. If the rocket impacts prior to 100 seconds then it should stop.
I don't know how to write the loops for the calculations.
Your code (as supplied) increments by 2.0 always. You can, however, adjust your increment to depend on the current value of Distance (and, presumably, the sign of the velocity, or it will do this on the ascent phase as well as the descent).