Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ language only, please. (In simple terms) 21. The Speed of Sound in Gases Whe

ID: 2075019 • Letter: C

Question

C++ language only, please. (In simple terms)

21. The Speed of Sound in Gases When sound travels through a gas, its speed depends primarily on the density of the medium. The less dense the medium, the faster the speed will be. The follow- ing table shows the approximate speed of sound at 0 degrees centigrade, meas- ured in meters per second, when traveling through carbon dioxide, air, helium, and hydrogen. Medium Carbon dioxide Air Helium Hydrogen Speed (Meters per Second) 258.0 331.5 972.0 1,270.0 Write a program that displays a menu allowing the user to select one of these four After a selection has been made, the user should enter the number of seconds it took for the sound to travel in this medium from its source to the location at which it was detected. The program should then report how far away (in meters) the source of the sound was from the detection location. Input Validation: Check that the user has selected one of the available menu choices. Do not accept times less than 0 seconds or more than 30 seconds.

Explanation / Answer

#include<stdio.h>

int main()

{

int a;

float b;

printf("Enter the serial number of the gases to calulate how far the gases move 1.Carbon dioxide 2.Air 3.Helium Hydrogen");

scanf("%d",&a);

printf(" Enter the number of seconds it travelled");

scanf("%d",&b);

if(a==1::b<=30::b>=30)

{

printf("The distance travelled is %d", b*258.0);

else (if(a==2&&b<=30&&b>=30)

printf("The distance travelled is %d", b*331.5);

else if(a==&&:b<=30&&b>=30)

printf("The distance travelled is %d", b*972.0);

else if(a==1&&b<=30&&b>=30)

printf("The distance travelled is %d", b*1270.0);

}

else

{

printf("Enter valid inputs");

}}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote