Forum Thread: Coding Help

Ok, this is gonna be a very short post but my question is I can't seem to figure what's wrong with my code when I run g++ through it to compile it. Whenever I add a semicolon after main() I keep getting expected unqualified id '{' token, but whenever I try it without the semicolon I get a ton of errors. Can anyone help me out? the code is here . Please and thanks. :)

5 Responses

Remember, semi colons close statements... You can't end main() before you start it, so don't put a semi colon there. Pay attention to the "ton of errors", working to fix them one by one. For starters, you're missing semi colons on the end of lines: 12, 13, 16, and need to remove the semi colon at the end of line 17. I can see a couple more errors, but start with those and try to follow the error messages you get when you try to compile. Ex: Did you define all your variables? Are there any other misplaced semi colons? Add some indentation inside your braces (and after your for loop) too to make it more readable so you'll have an easier time following the code.

Thank you very much... I'm still new to c++ in general but thank you for the help. :)

Of course. Best way to learn is to do it, and then try to figure out each error one at a time. Once you think you fixed the first error, recompile and see if you get farther. Often times, fixing one error will make several of the subsequent errors vanish (or at least change to more helpful errors) as the compiler can now properly interpret the rest of the code.

Every great coder started where you are now. They're great now only because they didn't give up. Keep at it. You'll get there.

(whoops) Fixed my cin and cout errors. Except fstream is being a pain, does fstream usually causes problems? :/

  • Missing semicolon, line 15
  • For loop does nothing
  • Incorrect use of getline?
  • Undeclared type of pB, line 20
  • Assuming pB is of type char, unsafe use of strcpy, line 21
  • Missing corresponding delete on dynamically allocated pB

What I don't understand is how this was compiled, if it was even compiled. What compiler are you using? Did you check any warnings/errors assuming your compiler failed to compile the code? Are you using the appropriate flags to check your code for errors? Did you do any research on any functions or operations? Looked at example code?

Share Your Thoughts

  • Hot
  • Active