Write a program that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
Think about how many test cases are needed to verify that your problem works correctly. (That is, how many different finish orders are possible?)
Input Validation: Only accept positive numbers for the times.
16. The Speed of Sound
The speed of sound varies depending on the medium through which it travels. In general, sound travels fastest in rigid media, such as steel, slower in liquid media, such as water, and lowest of all in gases, such as air. The following table shows the approximate speed of sound, measured in feet per second, in air, water, and steel.
Medium Speed (FT Per Second)
Air 1,100
Water 4,900
Steel 16,400
Write a program that displays a menu allowing the user to select air water, or steel. After
the user has made a selection, the number of feet a sound wave will travel in the selected
medium should be entered. The program will then display the amount of time it will take.
(Round the answer to four decimal places.)
Input Validation: Check that the user has selected one of the available menu choices.
Do not accept distances less than 0.
Im wondering if there is a formula i need to use, if so what is it.
#include <iostream>
usingnamespace std;
int main()
{
string run1, run2, run3;
double time1, time2, time3;
cout << " Enter the name of the runners and their time.\n Seperate name and time with a space.";
cout << "\n Enter the name of runner 1 and the time: ";
cin >> run1 >> time1;
cout << " Enter the name of runner 2 and the time: ";
cin >> run2 >> time2;
cout << " Enter the name of runner 3 and the time: ";
cin >> run3 >> time3;
{ //check if runner one came in first
if(time1 < time2 && time1 < time3)
{
if(time2 < time3) //if he did, then check to see where run2 and run3 placed
{
cout<<run1<<" came in first with a score of "<<time1<<endl;
cout<<run2<<" came in second with a score of "<<time2<<endl;
cout<<run3<<" came in third with a score of "<<time3<<endl;
}
else
{
cout<<run1<<" came in first with a score of "<<time1<<endl;
cout<<run3<<" came in second with a score of "<<time3<<endl;
cout<<run2<<" came in third with a score of "<<time2<<endl;
}
}
}
{ // check if 2 came first
if(time2 < time1 && time2 < time3)
{
if(time1 < time3) //if he did, then check to see where run1 and run3 placed
{
cout<<run2<<" came in first with a score of "<<time2<<endl;
cout<<run1<<" came in second with a score of "<<time1<<endl;
cout<<run3<<" came in third with a score of "<<time3<<endl;
}
else
{
cout<<run2<<" came in first with a score of "<<time2<<endl;
cout<<run3<<" came in second with a score of "<<time3<<endl;
cout<<run1<<" came in third with a score of "<<time1<<endl;
}
}
}
{ // check if 3 came first
if(time3 < time1 && time3 < time2)
{
if(time2 < time1) //if he did, then check to see where run1 and run2 placed
{
cout<<run3<<" came in first with a score of "<<time3<<endl;
cout<<run2<<" came in second with a score of "<<time2<<endl;
cout<<run1<<" came in third with a score of "<<time1<<endl;
}
else
{
cout<<run3<<" came in first with a score of "<<time3<<endl;
cout<<run1<<" came in second with a score of "<<time1<<endl;
cout<<run2<<" came in third with a score of "<<time2<<endl;
}
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
this is how i did it, with a lil help from pogrady in another post that i saw.
i got to do that speed of sound one too, only, its program 18 for me, so i got 2 more before i do that one.