Wrong output?

Dec 7, 2015 at 5:21pm
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;

cout << "Select a medium:\n";
cout << "1. Air\n";
cout << "2. Water\n";
cout << "3. Steel\n";
cout << "\n";
cout << "Enter your choice: ";
cout << "\n";
cin >> 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";
}

return 0;
}
Last edited on Dec 7, 2015 at 5:21pm
Dec 7, 2015 at 5:26pm
Running your program i get your expected output:
A·sound·wave·takes·9.0909·seconds·to·travel·10000.0000·feet·through·air


Can you explain what is actually wrong a bit more clearly please?
Dec 7, 2015 at 5:30pm
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.
Dec 7, 2015 at 5:32pm
I'm still not understanding sorry. "It says on the top..." what does that mean? top of what?
Dec 7, 2015 at 5:36pm
It just shows you what my errors are that's what I meant. When I submit the program it give's me feedback on what I need to fix.
Dec 7, 2015 at 5:38pm
Dec 7, 2015 at 5:42pm
Oh that's funny do you think it's the website's problem.
Dec 7, 2015 at 5:44pm
It's definitely not a c++ issue.
Dec 7, 2015 at 5:46pm
Well looks like i'll just have to message them, appreciate the help man.
Dec 7, 2015 at 5:51pm
Look at this part of the instructions:
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:"
Dec 7, 2015 at 6:16pm
I tried that and still not working.

new 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;

cout << "Select a medium:\n" << "1. Air\n"<< "2. Water\n" << "3. Steel\n";
cout << "\n";
cout << "Enter your choice: ";
cout << "\n";
cin >> 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";
}

return 0;
}
Dec 7, 2015 at 7:05pm
How about editing your post to add code tags?

You still haven't taken out all those extra line feeds.

Dec 7, 2015 at 10:23pm
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: ";
Dec 7, 2015 at 11:31pm
I finally figured it out. Finally finished it.
Topic archived. No new replies allowed.