Back to Problem Solutions forum
I am fine at programming (I think), but I am really stuglling with the maths behind problem 10. As far as I can see, the problem is just a variation of finding m and c from the straight line graph equation y=mx+c. Therefore I am trying to calculate m as "change in x / change in y", however, my answers are not coming out at all like the solutions.
changeInX = point2x-point1x;
changeInY = point2y-point1y;
gradient = changeInX/changeInY; // m
offset = point1y-(gradient*(point1x)); // c
I thought this was right, but I get 0 (I haven't bothered with rounding yet) for all the m values.
UPDATE:
I'm a moron. I got the X and Y positions in the division the wrong way around. This took me longer than I would care to admit to fix.