I am writing a c program that accepts two coordinate points from a rectangle, using a function distance, calculates the distance between using the formula distance = sqrt (x2-x1)^2+(y2-y1)^2
I know my beginning code is off base but I am just beginning in code and struggling to find correct codes.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#pragma warning (disable:4996)
int main()
{
float x1, x2, y1, y2, midpoint, xtotal, ytotal;
printf("Enter the first x coordinate: ");
scanf("%f", &x1);
printf("Enter the first y coordinate: ");
scanf("%f", &y1);
printf("Enter the second x coordinate: ");
scanf("%f", &x2);
printf("Enter the second y coordinate: ");
scanf("%f", &y2);
xtotal = (x2 - x1) * (x2 - x1);
ytotal = (y2 - y1) * (y2 - y1);
midpoint = sqrt(xtotal) + (ytotal);
printf("The distance of the coordinate is %f", midpoint);
return 0;
system("pause");
}