I am currently using Repl.it to run a program using C. The concept is simple
I am currently using Repl.it to run a program using C. The concept
is simple, I am writing a program to calculate the distance between 2 points. I have completed the program however it is not actually taking the square root. My code looks like this:
#include <stdio.h>
#include <math.h>
int main()
{
/*variable definition: */
float point1x, point1y, point2x, point2y, distance;
/* Promt user for Point1x */
printf (“Enter (x) for point1: \n”);
// Input point1x
scanf(“%f”, &point1x);
/*Prompt user for point1y */
printf (“Enter (y) for point1: \n”);
// Input point1y
scanf (“%f”, &point1y);
/*Prompt user for point2x */
printf (“Enter (x) for point2: \n”);
// Input point2x
scanf (“%f”, &point2x);
/*Prompt user for point2y */
printf (“Enter (y) for point2: \n”);
// Input point2y
scanf (“%f”, &point2y);
// Calculate the distance between point 1 and point 2
distance= fabs(((point2x – point1x)*(point2x – point1x))+((point2y – point1y)*(point2y – point1y)));
//Print the result
printf(“distance is :%f \n”, distance);
return 0;
}
I have tried “sqrt” but it comes up as undefined, I know that fabs is used in the math.h library so I implemented it into the code and while it does the rest of the math properly it doesn’t square what’s inside the parentheses. Is there another command I can use or am I doing something wrong? any guidance would be greatly appreciated!