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

In summary, the programmer is new to programming and is having trouble compiling a program. They typed in the correct commands, but they are in a different language than the compiler is expecting.
  • #1
mkbh_10
222
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
  • #2
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.
 
  • #3
I am new to programming , i will do wat u said ...
 
  • #4
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:
 
  • #5
Worked fine for me.
What did you type to compile?

Looks like you are in Ubuntu, so try:
g++ sinx3.cpp -o runMe
 
  • #6
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.
 
  • #7
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.
 
  • #8
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
 
  • #9
@ 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.
 

1. What are some common reasons for compilation errors?

Common reasons for compilation errors include syntax errors, missing or incorrect libraries, incorrect data types, and undefined variables.

2. How can I fix a syntax error in my code?

To fix a syntax error, carefully review your code for any missing or misplaced characters, such as missing parentheses or semicolons. Use your compiler's error messages to identify the specific line of code that is causing the error.

3. Why am I getting an "undefined variable" error?

This error means that you are trying to use a variable that has not been declared or initialized. Make sure to declare all variables before using them in your code.

4. What should I do if my program still won't compile after fixing all errors?

If you have fixed all errors and your program still won't compile, it could be due to a missing or incorrect library. Check that you have included all necessary libraries and that they are the correct versions for your code.

5. How can I prevent compilation errors in the future?

To prevent compilation errors, it is important to write clean and well-structured code. Use proper indentation and naming conventions, and consistently check for and fix any errors as you write your code. Also, regularly testing and debugging your code can help catch and fix any issues before they become bigger problems.

Similar threads

  • Programming and Computer Science
Replies
4
Views
906
  • Programming and Computer Science
Replies
2
Views
839
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
2
Views
369
  • Programming and Computer Science
Replies
32
Views
2K
  • Programming and Computer Science
3
Replies
70
Views
3K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
2
Replies
59
Views
5K
Back
Top