// Marvyn De La Torre    CS1A    Chapter 4, P.223, #18

/**************************************************************
* Calculate Speed of Sound
*
* This program calculates the time required for sound to travel
* a given distance through air, water, or steel.
*
* Input:
* Medium selected = choice
* Distance in feet = distance
*
* Output:
* Speed of sound = speed
* Time in seconds = time
**************************************************************/

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int choice;
    double distance, speed, time;

    cout << "Speed of Sound" << endl;
    cout << "1. Air" << endl;
    cout << "2. Water" << endl;
    cout << "3. Steel" << endl;
    cout << "Enter your choice: ";
    cin >> choice;

    cout << "Enter the distance in feet: ";
    cin >> distance;

    if (distance < 0)
    {
        cout << "Distance cannot be negative." << endl;
    }
    else
    {
        switch (choice)
        {
            case 1:
                speed = 1100;
                break;

            case 2:
                speed = 4900;
                break;

            case 3:
                speed = 16400;
                break;

            default:
                cout << "Invalid choice." << endl;
                return 0;
        }

        time = distance / speed;

        cout << fixed << showpoint << setprecision(4);
        cout << "Time: " << time << " seconds" << endl;
    }

    return 0;
}