i have a problem with an equation

i need to Compute the length of the line using the distance equation given below: √(x1-x2)2 + (y1-y2)2


ok i read everything but it does not compile i do not know why look

line = sqrt(((x1-x2)^2 + (y1-y1)^2)));
You can't use ^ like that in C++. Try using plain old multiplication.

-Albatross
i did this

line = sqrt((pow(x1,2)-pow(x2, 2)) + (pow(y1, 2) - pow(y1,2))); but in the graphic windows it shows this whenever i try to display it with the gout

-1.#IND00 algo asi porq
Whoa whoa whoa.

(a-b)^n is NOT the same as (a^n) - (b^n). You should know that, surely.

Again, though. I recommend plain old multiplication. :)

As for your error, that I can't solve as I am not on Windows and have lost my familiarity with that platform's API. Sorry.

-Albatross
Last edited on
I suppose that (pow(x1,2)-pow(x2, 2)) + (pow(y1, 2) - pow(y1,2)) happened to be a negative number.
Don't use pow for squaring. (x1-x2)*(x1-x2) would do..
The formula is completely wrong for the reason Albatross has pointed out. Under certain conditions, you'll end up trying to compute the square root of a negative number.
Topic archived. No new replies allowed.