/***************************************************************** CS167 C Programming, Section 2, Spring 1998 The bouncing ball This program calculates the distance traveled by a bouncing ball from the initial height, the ratio of the next height to the current height, and a cutoff height, below which the ball will not bounce. The values are input from the keyboard. The program counts the number of bounces. Author: Roger Hartley *****************************************************************/ #include int main() { float initialHeight, height, bounceRatio, heightCutoff, totalDistance; int numBounces = 1; printf("Initial height? "); scanf("%f", &initialHeight); printf("Bounce ratio? "); scanf("%f", &bounceRatio); printf("Height cutoff? "); scanf("%f", &heightCutoff); height = initialHeight * bounceRatio; totalDistance = initialHeight; while (height > heightCutoff) { printf("Height = %f distance = %f bounces = %d\n", height, totalDistance, numBounces); totalDistance += 2 * height; height *= bounceRatio; ++numBounces; } printf("From an initial height of %f ft. \n" "a ball with a bounce ratio of %f and a \n" "cutoff height of %f ft. will bounce %d times\n" "and travel a total distance of %f ft.\n", initialHeight, bounceRatio, heightCutoff, numBounces, totalDistance); return 0; }