You need to put a cin.get(); before the return 0;
Also the black window is commonly referred to as ze console window
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
> why didnt the tutorial tell me that
Because it ain't got nowt to do with c++, or the semantics of the language anyway. It depends on whether your IDE (integrated development environment) already has a built-in option to pause the program for viewing.
Some don't, some do.
If you ran your program from the command prompt there would be no need for the cin.get(); .
>a good tutorial for me
There are a few useful snippets at daniweb. Look there. But ultimately the best way to learn is to try your hand at a problem and post your queries here.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Unbelievable. 75 posts and you still don't know how to format your code ! I certainly hope you do not plan to turn in that to your instructor.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
all you did was comress it which to me makes it harder to read. .
Nope -- we didn't do that. In the future please hit the Preview button before posting so that you can see what it looks like.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>//Yes I did put in 'return 0' because it's bad
>//practice to leave it out and yada yada yada...
You're not getting away with this one. :) Explain why it's a bad practice, please.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>Then it's maybe only I who see it as bad practice?
No, you're not the only one, but it is a subjective issue.
>A program should exit by telling that it's finished and it all went as planned.
The language rules say that falling off the end of main will exit as if you said return 0; , so we're not talking about the undefined behavior problem from pre-standard C++ or C89. These two programs are completely identical:
int main()
{
}
int main()
{
return 0;
}
I can only think of two good reasons not to omit the return statement:
1) Consistency with other functions. main is a special function with special rules. I'm not sure that trying to match main with less special functions is a good idea because it trivializes the differences. This is what causes misunderstandings that produce the void main issue.
2) Symmetry when using an error return. If you're returning failure, you might find it strange not to match that with returning success:
#include <cstdlib>
int main()
{
//...
if ( something )
return EXIT_FAILURE;
//...
return EXIT_SUCCESS;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>I guess number 2 is most equal to my own logics.
Then we're of the same opinion.
>Btw... this became quite a nice hijacking of the thread
Threads often go off onto wildly different tangents. It's normal, and often very informative as you'll typically find one or more experts going back and forth.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401