/* --------------------------------------------------------------------- // Figure 5.4 Calling library functions. // --------------------------------------------------------------------- */ #include "tools.h" void main( void ) { double h; /* height of fall (m) */ double t; /* time of fall (s) */ double v; /* terminal velocity (m/s) */ banner(); puts( " Calculate the time it would take for a grapefruit\n" " to fall from a helicopter at a given height." ); printf( "\n Enter height of helicopter (meters): " ); scanf( "%lg", &h ); /* keyboard input for height */ if (h < 0) { /* exit gracefully after error */ fatal( " Error: height must be >= 0. You entered %g", h ); } else { /* otherwise, */ t = sqrt( 2 * h / GRAVITY ); /* calculate the time of the fall */ } v = GRAVITY*t; /* velocity of grapefruit at this time */ printf( " Time of fall = %g seconds\n", t ); printf( " Velocity of the object = %g m/s\n", v ); bye(); }