//
// source code: well.cc 
// purpose:     calculates arrival time of splash sound 
//                at surface for stone falling into well 
//                of given depth.
// author:      T. Hebbeker   
// version:     1.0, 2006-10-04
//

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
  cout << endl 
       << " program   === well ===   version 1.0 " 
       << endl << endl;

  // here we declare the variables needed

  // units: SI: meter=m, second=s, meter/second, etc.

  const double acceleration = 9.81;        // m/s^2
  const double velocity_sound = 340.;      // m/s
 
  double depth;                            // m
  double time_fall;                        // s
  double time_sound;                       // s
  double time;                             // s

  cout << " please enter depth of well in meters: ";
  cin >> depth;

  if(depth <= 0. || depth > 10000.)
  {
    cout << " illegal input: depth = " << depth << endl;
    return 1;  
  }

  time_fall = sqrt(2.*depth/acceleration);
  time_sound = depth/velocity_sound;
  time = time_fall + time_sound;

  cout << endl 
       << " splash can be heard " << time 
       << " seconds " << endl 
       << "   after dropping stone into well of depth = "
       << depth << " meters" 
       << endl; 

  return 0;
}


