Question: In C, using printf and scanf statements and creating constants when possible: Write a program to display characteristics of a ball thrown straight up into

In C, using printf and scanf statements and creating constants when possible:

Write a program to display characteristics of a ball thrown straight up into the air.

Ask the user for the initial height of the ball (in feet) and the initial velocity of the ball (in feet per

second). Validate that both values are greater than or equal to 0. Then, calculate and display:

  • The maximum height the ball will reach (in feet)

The ball will reach its maximum height after v/32 seconds, where v is the initial velocity

  • The number of seconds it will take for the ball to hit the ground (in 0.1 second intervals)

Calculate the height of the ball after every 0.1 second to determine when the ball height is

either 0 or a negative value

  • A table showing the height of the ball every 0.25 seconds until the ball is on the ground

Calculate the height of the ball after every 0.25 seconds, display both the time and the height,

and stop when the height is either 0 or a negative value

The formula for the height of the ball at any instance in time is:

h + v*t - 16*t2

where:

h = the initial height of the ball (in feet)

v = the initial velocity of the ball (in feet per second)

t = time (in seconds)

Make sure that you use the above formula and not any other formula you might find (otherwise, your

results and mine may not be the same).

Display a blank line between the inputs and the maximum height and time to hit the ground, and

between the maximum height and time to hit the ground and the table of heights every 0.25 second.

Hints:

  • Validation error messages are indented 3 spaces
  • Account for an initial velocity of 0 and/or an initial height of 0
  • When calculating when the ball will hit the ground, if the ball starts at an initial height of 0.0 ft.,

start with the balls height after 0.1 second

  • The table to display the balls height every 0.25 seconds may require a post-test loop, with the

first line of the table outside the loop

  • If the ball has an initial height of 0.0 ft., and an initial velocity of 0.0 ft. per sec., only display the

first line of the table

  • Use a tab to align the 2nd column (the Height column) in the table
  • Dont forget the blank line before Press any key to continue

Example Run #1:

(bold type is what is entered by the user)

Enter the initial height of the ball (in ft.): -10

The initial height must be greater than or equal to 0.

Enter the initial height of the ball (in ft.): 10

Enter the initial velocity of the ball (in ft. per sec.): -20

The initial velocity must be greater than or equal to 0.

Enter the initial velocity of the ball (in ft. per sec.): 20

The maximum height the ball will reach is xx.x feet.

The time for the ball to reach the ground is x.x seconds.

Time Height

0.00 10.0

0.25 xx.x

. xx.x

. xx.x

. xx.x

x.xx 0.0

Example Run #2:

Enter the initial height of the ball (in ft.): 10

Enter the initial velocity of the ball (in ft. per sec.): 0

The maximum height the ball will reach is 10.0 feet.

The time for the ball to reach the ground is x.x seconds.

Time Height

0.00 10.0

. xx.x

. xx.x

. xx.x

x.xx 0.0

Example Run #3:

Enter the initial height of the ball (in ft.): 0

Enter the initial velocity of the ball (in ft. per sec.): 20

The maximum height the ball will reach is xx.x feet.

The time for the ball to reach the ground is x.x seconds.

Time Height

0.00 0.0

0.25 xx.x

. xx.x

. xx.x

. xx.x

x.xx 0.0

Example Run #4:

Enter the initial height of the ball (in ft.): 0

Enter the initial velocity of the ball (in ft. per sec.): 0

The maximum height the ball will reach is 0.0 feet.

The time for the ball to reach the ground is 0.0 seconds.

Time Height

0.00 0.0

The example runs shows EXACTLY how your program input and output will look.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!