The first issue, as already explained is the missing row variable.
However, the second is of a similar ilk, regarding the second part of the code...
Your second loop uses
from 0-49 and
from 0-1. You are only accessing
j + 1
. As a result
are always accessing the same index (1) - resulting in identical values.
As a "proof of concept", you should really have a single loop from 0-99 and access the array index using a single variable. If the code is a stripped down version of production code, then you must access the
array using a operation of both
I see a third problem in that your array has 100 values, but the loop for
only reaches 50.
A "proof of concept" solution would be the following:
for (int i = 1; i < 100; ++i)
xGrid = abs(GridF[i] - GridF[i - 1]);
xGrid *= xGrid;
cout << "xGrid=" << xGrid << endl;
yGrid = abs(GridF[i] - GridF[i - 1]);
yGrid *= yGrid;
cout << "yGrid=" << yGrid << endl;
result = sqrt(xGrid + yGrid);
cout << "Equation : " << result << endl;
Also note the obvious facts:
1) You will get 99 outputs, not 100,
2) There is no validation (if required for min-max values),
3) Consideration for the double-int casting.