/* ------------------------------------------------------------------------- ** Figure 11.7 Improving the workmaster. ** Figure 6.13 The work() and drop() functions. ** ------------------------------------------------------------------------- */ #include "tools.h" /* #include commands and user #defined utilities */ void work( void ); /* function prototypes. */ void title( void ); double drop( double height ); void main( void ) { char more; /* repeat-or-stop switch */ banner(); title(); do { work(); printf( "\n Do you want to continue (Y/N)? : " ); scanf( " %c", &more ); more = toupper(more); } while ( more != 'N' ); bye(); } /* ----------------------------------------------------------------- */ void title( void ) { puts( " Calculate the time it would take for a grapefruit\n" " to fall from a helicopter at a given height.\n" ); } /* ------------------------------------------------------------------------ ** Perform one gravity calculation and print the results. */ void work( void ) { double h; /* height of fall (m) */ double t; /* time of fall (s) */ double v; /* terminal velocity (m/s) */ printf (" Enter height of helicopter (meters): " ); scanf( "%lg", &h ); t = drop( h ); /* calculate duration of fall. */ v = GRAVITY * t; /* velocity of grapefruit at impact */ printf( " Time of fall = %g seconds\n", t ); printf( " Velocity of the object = %g m/s\n", v ); } /* ------------------------------------------------------------------------ ** Calculate time of fall from a given height. */ double drop (double height) { if (height < 0) return 0; else return sqrt( 2 * height / GRAVITY ); }