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

A-The following table shows the approximate speed of sound in air, water, and st

ID: 3640899 • Letter: A

Question

A-The following table shows the approximate speed of sound in air, water, and steel.
Medium Speed
Air 1,100 feet per second
Water 4,900 feet per second
Steel 16,400 feet per second
Write a program that displays a menu allowing the user to select air, water, or steel. After the user has made a selection, he or she should ask to enter the distance a sound wave will travel in the selected medium. The program will then display the amount of time it will take.( round the answer to 4 decimal places).
Input validation: check that the user has selected one of the available choices from the menu. Do not accept distances less than 0.
loop through the program 5 times (like asking the user to select from the menu 5 times)

I have the program without looping, but I need help looping it. The program is below without looping.

#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 << " The Speed of Sound in a Medium ";
cout << "Please Select a Medium ";
cout << "1. Air ";
cout << "2. Water ";
cout << "3. Steel ";
cout << "Select the Desired Number and press Enter: ";
cin >> choice;
cout << "Now enter the distance (feet) the sound wave will travel in the selected medium, then press Enter: ";
cin >> distance;
cout << setprecision (4) << fixed;

if (distance == 0)
{
cout << " You must enter a value greater than zero ";
}
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 time it takes sound to travel this distance in the selected medium is ";
cout << amountOfTime;
cout << " seconds" << endl;
}
return 0;
}

Explanation / Answer

Here ya go! All I did was encase the program in a simple for loop, that ran it 5 times. And at the end of the for loop I paused the program, and at the beginning of the loop I clear the screen. Hope that helps! #include #include 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 for(int i = 0; i < 5; ++i) { system("cls"); cout
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