Funny things happening outside of function
Hi again all,
This time i'm having trouble in returning a value from a class function. The function is supposed to work out the euclidian distance between two points i.e. sqrt( (x1-x2)squared + (y1-y2)squared). The distance i'm working out is over 10 points. When I was running the function in MSDOS it worked fine, however now that i'm tyring to run the program in MFC windows things aren't quite working.
Here is the function for calculating the length:
where m_XYCoOrds is a 2d array with i referring to the current point (0-9) and [i] being x, [i] being y.
int CLine::SectionLength(int m_XYCoOrds)
int TotalLength =15;
int SectionLength =0;
int Xvariance = 0;
int Yvariance = 0;
variance = (m_XYCoOrds[i] - m_XYCoOrds[i+1]);
Yvariance = (m_XYCoOrds[i] - m_XYCoOrds[i+1]);
SectionLength = (sqrt( (Xvariance*Xvariance) + (Yvariance*Yvariance)));
TotalLength = TotalLength + SectionLength;
The TotalLength value returned is stored in the object under the name m_Length.
When I try and see what the value is i call this in the View.cpp file
this has been producing the value -842150451
CString test; //string to show the total length number
int test3 = pDoc->LineArray.m_Length;//get the first lines length
test.Format(_T("test length is %d",test3));
I don't think its just a problem with the test.Format line as I can access other data members in the class that are initialised fine.
As a quick test before wasting anyones time I set the function to just return the value 15, however m_Length was still showing -842150451. Can anyone tell me where this magic number has come from.
Any help whatsoever is again greatly appreciated.