Code:#include <stdio.h> int main(); { printf("Enter desired grade"); char grade; scanf("%c", &grade); return 0; }
error expected a identifier or '(' before '{'
(I have no idea whats even wrong with this)
Code:#include <stdio.h> int main(); { printf("Enter desired grade"); char grade; scanf("%c", &grade); return 0; }
error expected a identifier or '(' before '{'
(I have no idea whats even wrong with this)
Last edited by tmac619619; 10-08-2012 at 08:36 PM.
You're missing a comma in there.Code:scanf("%c", &grade);
And it's "int main(void)"
And be sure to "return 0" at the end of the program.
[EDIT] Oh, and no semi-colon after "main()"!
Code:int main();
Last edited by Matticus; 10-08-2012 at 08:36 PM.
I noticed that i solved the problem as soon as i removed the ; from int main();
Why?
"...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'm sorry i'm very newb at this lingo.
int main ();
int main()
whats the difference? I know the ';' effectively "concludes" a statement or command.
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.Originally Posted by tmac619619
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.
This explanation does not apply in this case since substituting the braces with a semi-colon changes the meaning of the code.Originally Posted by stahta01
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
You can consider
I am wrong; the semi colon in this case makes it a function prototype.Code:int main ();
This below is a function with a very small function body.Code:int main (){;}
You are going to have to wait for a person who can explain better that I for a clearer answer.Code:int main () { ; }
Use laserlight Answer; she is the expert here on C++ and better on C than me.
Tim S.
Last edited by stahta01; 10-08-2012 at 08:56 PM.
"...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).Originally Posted by stahta01
The former does not constitute a complete program; the latter is a complete (though not particularly useful) program. They are definitely not equivalent.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)