fork download
  1. //OrinTill Qimid CS1A Chapter 4, P. 224, 19
  2. //
  3. /**************************************************************
  4.  * compute speed of sound
  5.  *
  6.  * ____________________________________________________________
  7.  * This program will claculate how far away the source of the sound is coming from.
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * choice : the choice of medium.
  11.  * sound : the given time.
  12.  * OUTPUT
  13.  * air : distance of sound travel through the air.
  14.  * carbon : distance of sound travel through carbon dioxide.
  15.  * helium : the distance of sound travel through helium.
  16.  * hydrogen : the distance of sound travel through hydrogen.
  17.  * The manual output that shows the choices.
  18.  **************************************************************/
  19. #include <iostream>
  20. #include <iomanip>
  21. #include <cmath>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. float sound,
  27. carbon,
  28. air,
  29. helium,
  30. hydrogen;
  31. int choice;
  32. cout<<"---------------------------------------------"<<endl;
  33. cout<<" Medium Speed(Meters per seconds)"<<endl;
  34. cout<<"---------------------------------------------"<<endl;
  35. cout<<"1.Carbon Dioxide 258.0"<<endl;
  36. cout<<"2.Air 331.5"<<endl;
  37. cout<<"3.Helium 972.0"<<endl;
  38. cout<<"4.Hydrogen 1,260.0"<<endl;
  39. cout<<"---------------------------------------------"<<endl;
  40. cout<<"please pick a number from 1 to 4 for your medium and enter how long it too for the sound to reach your destination";
  41. cin>> choice;
  42. if (choice<1)
  43. {
  44. cout<<"thats not a vaild input"<<endl;
  45. }
  46. else if (choice>4)
  47. {
  48. cout<<"thats not a vaild input"<<endl;
  49. }
  50. cin>> sound;
  51. if (choice==1)
  52. {
  53. carbon = sound *258.0;
  54. cout<<"The souce of the sound is coming from "<<carbon<<" meters away";
  55. }
  56. else if (choice==2)
  57. {
  58. air = sound * 331.5;
  59. cout<<"The souce of the sound is coming from "<<air<<" meters away";
  60. }
  61. else if (choice==3)
  62. {
  63. helium = sound * 972.0;
  64. cout<<"The souce of the sound is coming from "<<helium<<" meters away";
  65. }
  66. else
  67. {
  68. hydrogen = sound * 1260.0;
  69. cout<<"The souce of the sound is coming from "<<hydrogen<<" meters away";
  70. }
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty