//Saliha Babar CS1A Chapter 4, Page 223, #18
//
/************************************************************************
*
* CALCULATE TIME FOR A SUBSTANCE TO TRAVEL
* ______________________________________________________________________
* This program allows user to choose from 3 substances and calculates the
* time taken of that substance to travel.
*
* Calculation is based on the formula
* time taken = distance / speed
*________________________________________________________________________
* INPUT
* choice : user choice from 3 substances
*
* OUTPUT
* time taken : time taken for the substance to travel
* *********************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int choice; // INPUT - user choice of substance
double distance; // INPUT - distance entered
int const airSpeed = 1100; // INPUT - constant speed of air
int const waterSpeed = 4900; // INPUT - constant speed of water
int const steelSpeed = 16400; // INPUT - constant speed of steel
double time; // OUTPUT - time taken to travel
cout << "Choose a selection of substance\n";
cout << "1 - air\n";
cout << "2 - water\n";
cout << "3 - steel\n";
cin >> choice;
if ( choice >= 1 && choice <=3)
{
cout << "Now, enter a distance that the substance travel in meters .\n";
cin >> distance;
if (distance > 0)
{
cout << fixed << showpoint << setprecision(4);
switch (choice)
{
case 1 :
time = distance / airSpeed ;
cout << "Time taken is " << time << " seconds\n";
break;
case 2 :
time = distance / waterSpeed ;
cout << "Time taken is " << time << " seconds\n";
break;
case 3 :
time = distance / steelSpeed ;
cout << "Time taken is " << time << " seconds\n";
break;
}
}
else
{
cout << "Only enter positive distance. Run the program again\n";
}
}
else
{
cout << "Invalid Choice, run the program again with numbers 1-3\n" ;
}
return 0;
}