// FILE: Swimmer.cpp // PRINTS DISTANCES BETWEEN A SWIMMER AND THE FAR SIDE OF THE POOL // The swimmer keeps cutting the distance by 2/3 her body length // on each stroke, until she is close enough to touch the edge of the pool. #include int main () { // Local data ... const double body_length = 5.8; // swimmer body length in feet double initial_distance; // starting distance of swimmer double distance; // distance between swimmer and other side cout << "Enter the initial distance of the swimmer from " << endl; cout << "the opposite side of the pool in feet: "; cin >> initial_distance; // Cut the distance between the swimmer and the opposite side // by 2/3 the swimmer's body length until she is close // enough to touch the edge. cout.setf (ios::fixed); cout.precision (2); distance = initial_distance; while (distance >= body_length) { cout << "The distance is " << distance << endl; distance -= body_length / 1.5; // reduce distance } // end while // Print final distance before touching the opposite edge. cout << endl; cout.precision (1); cout << "The last distance before the swimmer touches the edge" << endl; cout << "on the opposite side of the pool is " << distance << endl; return 0; }