the problem is that the output for both equations is wrong, it doesn't do the math properly and I assume it has to do with the variable types I'm using but am not sure. Any help would be greatly appreciated. P.S. I am using the latest version of DEV-C++
Can you elaborate on that please? In distance formula, when you're doing (x2 - x1) all you are doing really is meaning to find the distance between the two points. So absolute value is perfectly valid for this situation in my opinion.
i have fixed the code slightly and made all the variable types double, however, for some reason, it still doesn't get the right answer. The distance between say (1,2) and (3,4) is sqrt of 8 however the program displays sqrt of 0. ( i got rid of the final distance and distanceb4sqrt because i dont care the exact number, only the sqrt) The midpoint calculator also only displays in integers, not in decimals. I'm very confused and am going to try the asolute value way of solving. Slightly edited code:
//This program is a start to solve basic coordinatre plane distances and midpoints
using namespace std;
My conclusion if the absolute value code doesn't work is that i'll just make separate functions for midpoint and distance or a menu to select which to do before inputting the four variables. Thanks for all the feedback!
The formula is incorrect for finding the distance. It should be:
sqrt (x2 - x1) ^ 2 + (y2 - y1) ^ 2)
Although, to write powers in C++, you need to do pow(a,b) where a is the number and b is the power it's being raised to. sqrt(a) find the root of a. To use pow() and sqrt(), you need to #include <cmath>.