Hello I made this program. Everything runs but on my programming lab it says the contents of your standard output is incorrect. Here's the expected result. Mine looks exactly the same yet it's wrong. Any help appreciated.
Select·a·medium:↵
1.·Air↵
2.·Water↵
3.·Steel↵
↵
Enter·your·choice:1·↵
·Enter·the·distance:10000·↵
·↵
A·sound·wave·takes·9.0909·seconds·to·travel·10000.0000·feet·through·air.↵
My code:
#include <iostream>
#include <iomanip>
using namespace std ;
int main ()
{
const int A = 1100;
const int W = 4900;
const int S = 16400;
double distance;
int choice;
if (choice > 0 && choice < 4)
{
cout << "Enter the distance: \n";
cin >> distance;
if (distance > 0)
{
cout << "A sound wave takes ";
cout << fixed << setprecision(4);
switch (choice)
{
case 1: cout << distance / A << " seconds to travel " << distance << " feet through air.\n";
break;
case 2: cout << distance / W << " seconds to travel " << distance << " feet through water.\n";
break;
case 3: cout << distance / S << " seconds to travel " << distance << " feet through steel.\n";
break;
}
}
else
{
cout << "Distance must be greater than zero.";
}
}
else
{
cout << "The valid choices are 1 through 3. Run the\nprogram again and select one of those.\n";
}
Well it doesn't show any errors on my program but it says on the top that
⇒ The contents of your standard output is incorrect.
⇒ Attention: the difference between your stdout and the expected stdout is just a question of spacing.
But it seems like the spacing and everything is on point I just don't know why it's incorrect.
Menu. The menu should look exactly like this:
Select a medium: 1. Air 2. Water 3. Steel
Enter your choice:
Does your output look exactly like the example? Notice all the selections are on the same line. No extra space between the "Select" line and the "Enter". And it appears that the user entry should happen on the same line as "Enter your choice:"
if (choice > 0 && choice < 4)
{
cout << "Enter the distance: \n";
cin >> distance;
if (distance > 0)
{
cout << "A sound wave takes ";
cout << fixed << setprecision(4);
switch (choice)
{
case 1: cout << distance / A << " seconds to travel " << distance << " feet through air.\n";
break;
case 2: cout << distance / W << " seconds to travel " << distance << " feet through water.\n";
break;
case 3: cout << distance / S << " seconds to travel " << distance << " feet through steel.\n";
break;
}
}
else
{
cout << "Distance must be greater than zero.\n";
}
}
else
{
cout << "The valid choices are 1 through 3. Run the\nprogram again and select one of those.\n";
}
Ok I figured out where the problem is at. It's showing this line down below is incorrect. It says that I need to fix the spacing?
cout << "Enter your choice: ";