//Xinnuo Wang CS1A chapter 4, p.224 #19
//
/*******************************************************************************
*
* Caculate meters the sound traveled
* _____________________________________________________________________________
* This program accepts the seconds of the sound traveled and caculate the
* meters.
*
* Computation is based on the formula:
* meters = speed * seconds
* _____________________________________________________________________________
* INPUT
* Choice : The choice you made to decide a type of gase.
* Seconds : The seconds the sound traveled
* OUTPUT
* Meters : The meters the sound traveled
*
******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
int choice; // INPUT - The choice you made to decide a type of gase.
float seconds; //INPUT - The seconds the sound traveled
float meters; //OUTPUT - The meters the sound traveled
cout <<"===== MENU ====="<< endl;
cout <<"1.Carbon Dioxide"<< endl;
cout <<"2.Air"<< endl;
cout <<"3.Helium"<< endl;
cout <<"4.Hydrogen"<< endl;
//
//Data Input
cout<<"Enter a number"<< endl;
cin >> choice;
cout << "Enter the seconds"<<endl;
cin>> seconds;
//
//Check
if (seconds<0 || seconds > 30)
{
cout << "Invalid time input" << endl;
return 0;
}
//Output
switch(choice)
{
case 1:
{
meters= seconds * 258;
cout<< "The sound traveled " << meters <<" meters."<<endl;break;
}
case 2:
{
meters= seconds * 331.5;
cout<< "The sound traveled " << meters <<" meters."<<endl;break;
}
case 3:
{
meters= seconds * 972.0;
cout<< "The sound traveled " << meters <<" meters."<<endl;break;
}
case 4:
{
meters= seconds * 1270.0;
cout<< "The sound traveled " << meters <<" meters."<<endl;break;
}
default:
cout <<"Invalid choice"<< endl;
}
return 0;
}