Starting from:

$20

CSE100 Lab 4 Watermelon Program Solution

Suppose Dave drops a watermelon off a high bridge and lets it fall until it hits the water. If we neglect air resistance, then the distance d in meters fallen by the watermelon after t seconds is d = 0.5 * g* t2, where the acceleration of gravity g = 9.8 meters/second2. Write a program that asks the user to input the number of seconds that the watermelon falls and the height h of the bridge above the water. The program should then calculate the distance fallen for each second from t = 0 until the value of t input by the user. If the total distance fallen is greater than the height of the bridge, then the program should tell the user that the distance fallen is not valid.

Sample Run 1:

Please input the time of fall in seconds:

2

Please input the height of the bridge in meters:

100

Time Falling (seconds)        Distance Fallen (meters)

******************************************************

0                       0

1                        4.9

2                        19.6

Sample Run 2:

Please input the time of fall in seconds:

4

Please input the height of the bridge in meters:

50

Time Falling (seconds)   Distance Fallen (meters)

**************************************************

0                  0

1                   4.9

2                   19.6

3                   44.1

4                   78.4

Warning-Bad Data: The distance fallen exceeds the height of the bridge

More products