[SOLVED] I'm Making Nim, the game, and I was wondering where my syntax errors are??
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The version of gcc I'm using (4.7.1) gives clearer error messages:
Code:
make nim.o
g++ -Wall -Wextra -Wformat=2 -g -ansi -pedantic -std=c++98 -c -o nim.o nim.cc
nim.cc: In function ‘int main()’:
nim.cc:29:13: error: ‘else’ without a previous ‘if’
nim.cc:31:13: error: ‘else’ without a previous ‘if’
nim.cc:36:13: error: ‘else’ without a previous ‘if’
nim.cc:38:13: error: ‘else’ without a previous ‘if’
nim.cc:43:13: error: ‘else’ without a previous ‘if’
nim.cc:45:13: error: ‘else’ without a previous ‘if’
nim.cc:49:13: error: expected ‘)’ before ‘cout’
nim.cc:58:17: error: ‘else’ without a previous ‘if’
nim.cc:65:17: error: ‘else’ without a previous ‘if’
nim.cc:72:17: error: ‘else’ without a previous ‘if’
make: *** [nim.o] Error 1
And indeed your ifs aren't connected to your elses (remember this isn't python, indentation doesn't affect the meaning). Also, you don't have a closing brace for your main() function.
Did you write up the whole program and only then try to compile it? It's much easier to build up a program in small steps, ensuring every step is correct.
...by starting with a small program that works and compiles, and building up. Honestly, that's the only way you're going to learn to write C++ right, if you'll allow me to turn a phrase.
However, almost all of your errors will be solved by putting a '{' after the ')' of an 'if' statement, and a '}' at the end of the block (normally before the 'else'). For example:
Please, for the love of Cthulhu, start with something small (like the code I posted in this post) and work up to the whole thing. There are so many syntax errors in your code that you are not going to be able to fix it without a much better knowledge of C++ than you currently have. If you start small, then any errors you have should be far more easily fixable than the code you currently have.
And I'm sorry, I shouldn't have got irritated either. I'm going to put on some laundry, and when I get back I will fix part of your code for you so you can see what we're aiming for...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.