I format my braces like this:
1 2 3 4
|
while(true) {
//code...
}
|
Hopefully if you put the opening brace on the same line as the while or if or for, then you won't be tempted to put a semicolon in between. As
L B was saying do this first:
while() {}
Then go back and fill in the details.
The compiler won't warn about this this situation, because while loops with a null statement are sometimes valid code. It should with a for loop though.
Speaking of warnings, do you have them at the highest level? Under g++ I use:
If I want to be particularly pedantic, I can use
which promotes warnings to errors.
With your code, you need more functions. Main has 280 lines - that is way too much. Having more functions can make code easier to debug because you can use the step-over facility to to execute all of a function, as opposed to stepping into it, doing 1 line at a time.
IMO, your code could do with more comments to explain what is going on - this might help you identify what code should go in a function. If I was a maintenance programmer, I would have to stare at your code and try and figure out what is happening. More functions makes it easier for the maintenance programmer too. This is important, because one day you might be working in industry or on an open source project.
Can you change your printf statements to std::cout ?
And avoid having
using namespace std;
- just put
std::
before each std thing.
this:
counter = counter + 1;
can be written:
counter++;
You could change all your for loops to look more like this:
for(counter = 0; counter < (boardSize / 2); counter++)
Just so you know, there are also operators like +=, -=, *= and /=, which work like this:
MyVar += 2; //same as MyVar = MyVar + 2;
With statements that come after an if or loop, I always use braces even if it is only 1 statement - this will save you one day when you add more code. Indentation can show the intent, but it can make errors like that hard to see.
Hope all goes well.