Do you spot any statement or code which might not be acceptable in other compilers other than GCC? |
I can't say because I use g++ under KDevelop on linux. gcc stands for gnu c compiler, as I said above, you must be using g++ the C++ compiler.
Now some observations:
int n, idx = 0, radius, x, y, k, i, xi, yi, dead;
I look at this and think what do all these mean? I am a big fan of naming variables with words rather than a single letter, because helps someone to understand straight away, and can help prevent errors in code. Also initialise them at the same , it will save you one day.Try this instead:
1 2 3 4 5 6 7 8 9 10
|
int n=0; //don't know what n is give it a better name
int idx= 0; //don't know what idx is give it a better name
int radius = 0; //The radius of a circle used for what?
int XOrdinate = 0; //The X part of a coordinate
int XOrdinate = 0; //The Y part of a coordinate
int k = 0; //don't know what k is give it a better name
int i=0; //don't know what i is give it a better name
int xi=0; //some relationship between x and i give it a better name
int yi=0; //some relationship between y and i give it a better name
int dead =0; //something died or is dead give it a better name
|
This seems really long winded, but it is much better alround. If someone is judging your code, doing this will earn you some brownie points.
I could probably sit here and figure out what they all mean, but I'd rather not - better to make it obvious right at the start.
The other thing to realise is, in the real world there are systems programmers & maintenance programmers. If you were the systems guy, and I was the maintenance guy - I would have something to say to your boss about this code. And your boss might fire you.
I am not trying to be really harsh - I am trying to point you towards some good practice.
what if k == 0? you should check that k > I and take action if it isn't.
if (pow(xi - x, 2) + pow(yi - y, 2) <= pow(radius, 2))
You should get a lot of warnings doing this - these variable are all ints - pow takes doubles. It works because the compiler automatically casts the int to a double. It makes me wonder if they should be doubles in the first place .
cout << dead << " DEAD " << k - dead << " ALIVE\n";
if you are using cout, don't use \n, do this instead with endl
cout << dead << " DEAD " << k - dead << " ALIVE" << endl;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int indx = 0;
for (int i = 1; i < len; i++)
{
if (pt[i] == ',')
{
c = '\0';
break;
}
else
{
numChar[indx] = pt[i];
}
indx++;
|
Why put indx++ where it is, why not use numChar[i-1], then you wont need indx at all.
Hope this helps