>compiler says "main must return int"
>teacher says it's fine
Your compiler is right and your teacher is wrong. main has never returned anything but int in C or C++. If a compiler allows it then it's a non-standard extension to the language and you can't expect your code to do anything meaningful on another compiler. The following definition for main will work everywhere without fail in any version of either C or C++:
int main()
{
return 0;
}
However, the recommended C style (that also works perfectly for C++) is
int main(void)
{
return 0;
}
to promote continuity with the way declarations are handled, and the recommended C++ style is
int main()
{
}
because C++ will return 0 (for success) automagically, thus removing the only argument that idiotic void mainers constantly spout about returning 0 taking too much effort. The same feature is in the latest version of C, but because it isn't widely implemented yet, you should continue to work with the common subset of "old" C and "new" C.
If your teacher disagrees then direct him here and I'll be happy to explain in detail why he's stupid.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
When you get your program running your in for another surprise. Your program will say, for instance, that 3/5 = 0. The problem is that onefraction.num and onefraction.den are integrs and when you divide integers you just get their integer quotient. Something like this will work: decimal = (1.0*onefraction.num)/onefraction.den;, or you could use a cast.
murschech
Junior Poster in Training
60 posts since Dec 2004
Reputation Points: 21
Solved Threads: 1