fork download
  1. /*******************************************************************************
  2.  * Aiden Stannard // CS1A // Chapter 4 Homework: Challange 19# // 9/26/2026
  3.  *
  4.  * Distance Traveled Through Gases
  5.  *
  6.  * This program recieves an selection from a menu itemized by different gases
  7.  * and than receives the time it took for sound to travel through the selected
  8.  * gas, outputing the distance the sound traveled.
  9.  *
  10.  * Inputs:
  11.  * 1)CO2
  12.  * 2)Air
  13.  * 3)Helium
  14.  * 4)Hydrogen
  15.  *
  16.  * Select the number corrosponding to the medium that you are measuring ___
  17.  * Now enter the time in seconds it took for the sound to travel ___
  18.  *
  19.  * Output: The sound traveled ___ Meters
  20.  ******************************************************************************/
  21. #include <iostream>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. int menuSelect;
  27. float seconds;
  28.  
  29. cout << "1)CO2\n" << "2)Air\n" << "3)Helium\n" "4)Hydrogen" << endl;
  30. cout << "\nSelect the number corrosponding to the medium that you are "
  31. "measuring" << endl;
  32. cout << "Now enter the time in seconds it took for the sound to travel\n";
  33.  
  34. cin >> menuSelect;
  35. cin >> seconds;
  36.  
  37. if (menuSelect == 1)
  38. cout << "The sound traveled " << seconds * 258.0 << " Meters" << endl;
  39. else if (menuSelect == 2)
  40. cout << "The sound traveled " << seconds * 331.5 << " Meters" << endl;
  41. else if (menuSelect == 3)
  42. cout << "The sound traveled " << seconds * 972.0 << " Meters" << endl;
  43. else if (menuSelect == 4)
  44. cout << "The sound traveled " << seconds * 1270.0 << " Meters" << endl;
  45. else
  46. cout << menuSelect << " Is not a valid selection. Try Again." << endl;
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
1.5


stdout
1)CO2
2)Air
3)Helium
4)Hydrogen

Select the number corrosponding to the medium that you are measuring
Now enter the time in seconds it took for the sound to travel
The sound traveled 1458 Meters