Troubleshooting Compilation Errors: Why Won't My Program Compile?

AI Thread Summary
The discussion centers around troubleshooting compilation errors in a program. Participants emphasize the importance of sharing code directly in the forum rather than through images for faster assistance. They recommend including specific compiler error messages and line numbers to facilitate better guidance. A user is advised to use the command "g++ sinx3.cpp -o runMe" for compilation on Ubuntu. It is suggested that the first three lines of the code may not be recognized as comments, leading to syntax highlighting issues. Users recommend changing double semicolons to double slashes for comments and removing the problematic lines. Additionally, there is a clarification that the user is coding in C, not C++, and a note on best practices regarding namespace usage in future programming.
mkbh_10
Messages
217
Reaction score
0
Tell me why am i not able to compile this program, the terminal lists various errors

http://tinypic.com/r/1zxtm5h/7
 
Technology news on Phys.org
Two tips:

1. It's a lot faster for other people here if you paste your code directly into your posting instead of making us wait for a large picture to download. To keep the code formatted properly, enclose it in [ CODE ] and [ /CODE ] tags (remove the spaces that I added between the brackets).

2. It helps a lot if you tell us what compiler error messages you got, and what line they refer to.
 
I am new to programming , i will do wat u said ...
 
Think of it this way: when you go to the doctor, you don't just tell him, "I hurt." You tell him where you hurt and what kind of pain it is. :smile:
 
Worked fine for me.
What did you type to compile?

Looks like you are in Ubuntu, so try:
g++ sinx3.cpp -o runMe
 
I may be off here, but it appears that those first three lines are supposed to be comments but aren't being treated as such. If you notice the words 'buffer' 'is' and 'for' are all syntax highlighted. Also the text between the single quotes in don't and file's is highlighted as if it were a string constant.

I recommend changing those double semicolons to double slashes like the rest of the comments.
 
Yeah it seems you have written it in the Emacs *scratch* buffer and then saved it to file, remove the first 3 lines. Then try to compile with the command already written here.
 
i don't know if this will help your problem at all but I am also new to c++ and i have just gotten in the habit of including: "#include <cstdlib>" ; and "using namespace std". in all of my programs
 
@ Bad
He's writing in C, not C++
But aside from that, namespace std - in the future you should consider only import those that actually needed.
But at the moment it's okay.
 
Back
Top