- In the extension bar, click the AdBlock Plus icon
- Click the large blue toggle for this website
- Click refresh
- In the extension bar, click the AdBlock icon
- Under "Pause on this site" click "Always"
- In the extension bar, click on the Adguard icon
- Click on the large green toggle for this website
- In the extension bar, click on the Ad Remover icon
- Click "Disable on This Website"
- In the extension bar, click on the orange lion icon
- Click the toggle on the top right, shifting from "Up" to "Down"
- In the extension bar, click on the Ghostery icon
- Click the "Anti-Tracking" shield so it says "Off"
- Click the "Ad-Blocking" stop sign so it says "Off"
- Refresh the page
- In the extension bar, click on the uBlock Origin icon
- Click on the big, blue power button
- Refresh the page
- In the extension bar, click on the uBlock icon
- Click on the big, blue power button
- Refresh the page
- In the extension bar, click on the UltraBlock icon
- Check the "Disable UltraBlock" checkbox
- Please disable your Ad Blocker
- Disable any DNS blocking tools such as AdGuardDNS or NextDNS
- Disable any privacy or tracking protection extensions such as Firefox Enhanced Tracking Protection or DuckDuckGo Privacy.
If the prompt is still appearing, please disable any tools or services you are using that block internet ads (e.g. DNS Servers, tracking protection or privacy extensions).
Question
Jackerman23
So I am suppose to write a program that displays a menu for allowing the user to select air, water or steel. After the user has made a selection, s(he) should be asked to enter the distance a sound wave will travel in the selected medium, then whether this distance is in feet or miles. The program will then display the amount of time it will take for sound to travel this distance (in seconds).
Medium / Speed
Air = 1,100 feet per second
Water = 4,900 feet per second
Steel = 16,400 feet per second
So this is what I got so far:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int choice;
int distance;
double amountOfTime;
const double Air = 1100; //feet per second
const double Water = 4900; //feet per second
const double Steel = 16400; //feet per second
cout << "\t\tThe Speed of Sound \n";
cout << "Please select your medium \n\n";
cout << "1. Air \n";
cout << "2. Water \n";
cout << "3. Steel \n";
cout << "Enter your choice: ";
cin >> choice;
cout << "Enter the distance the sound wave will travel: ";
cin >> distance;
cout << setprecision (4) << fixed;
cout <<
if (distance == 0)
{
cout << "Distance must be greater than zero\n";
}
else if (choice >= 1 && choice <=3)
{
switch (choice)
{
case 1: amountOfTime = distance / Air;
break;
case 2: amountOfTime = distance / Water;
break;
case 3: amountOfTime = distance / Steel;
}
cout << "The amount of time it will take to travel is ";
cout << amountOfTime;
cout << " seconds" << endl;
}
return 0;
}
The program works but I still need help in writing the code to ask the user on whether if they want the distance in feet or miles within my program and with a conversion in the code that will display the result of the feet or miles that they will want inputted because so far the distance I ask the user only displays the standard of feet, thanks!
Link to comment
https://www.neowin.net/forum/topic/1185331-help-with-the-speed-of-sound-c-program/Share on other sites
4 answers to this question
Recommended Posts