"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

I noticed that i solved the problem as soon as i removed the ; from int main();

Why?

With the semi-colon there, you declared, but did not define (implement) the main function. Later on, you will find that this becomes useful when you have many functions, some of which call others. You can then declare all of them near the top and not have to worry about which order you define them.

Anyway, the point is that since that is only a declaration of main, you end up with a block of code in the middle of nowhere, instead of being the body of the main function.

Originally Posted by stahta01

Code:

The braces are multi-line block everywhere or nearly everywhere you can use {} can instead be a single line block as in just a single ";".

This explanation does not apply in this case since substituting the braces with a semi-colon changes the meaning of the code.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

No, the former is a declaration of the main function that declares that the main function returns an int and takes an unknown number of arguments. The latter is a definition of the main function that declares that the main function returns an int and takes no arguments, then implements the main function to do nothing (besides implicitly return 0, in the case of C99 and later).

The former does not constitute a complete program; the latter is a complete (though not particularly useful) program. They are definitely not equivalent.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.