So, I was trying to code a program which asks the user to input the points of a graph to calculate the euclidean distance and uses it as a radius to give the area of a circle.
Here's my code:
/*You have to take four points(x1,y1,x2,y2) from the user and use it radius to find area of a circle. To find the distance between these points, you will use the Euclidean distance formula.*/
#include <stdio.h>
#include <math.h>
#define PI 3.14
float euclideanDistance(float x1, float x2, float y1, float y2)
{
float ed = 0;
ed = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
return ed;
}
int areaOfCircle(float x1, float y1, float x2, float y2, float(ed)(float x1, float y1, float x2, float y2))
{
return PI * (*ed)(x1, y1, x2, y2) * (*ed)(x1, y1, x2, y2);
//not sure if it's correct or not. No error squiggles.
}
int main()
{
float x1, y1, x2, y2;
float (*fptr)(float, float, float, float);
fptr = euclideanDistance;
printf("Enter the four points x1,y1,x2,y2 to calculate the Euclidean Distance.\n");
printf("x1:");
scanf("%f", &x1);
printf("y1:");
scanf("%f", &y1);
printf("x2:");
scanf("%f", &x2);
printf("y2:");
scanf("%f", &y2);
;
printf("The euclidean distance is %f", fptr(x1, x2, y1, y2));
printf("The area of the circle which has the above mentioned Euclidean Distance as it's radius is: %f", areaOfCircle(x1, x2, y1, y1, fptr(x1, y1, x2, y2))); //error in this printf.
return 0;
}
There are two problems over here.
I am not getting how to use the function euclideanDistance as a radius in areaOfCircle and second is how to implement it in my main function.
For the second problem In the VS Code it's showing me the error that.
{"message": "argument of type "float" is incompatible with parameter of type "float (*)(float x1, float y1, float x2, float y2)""}
Please explain what I'm doing wrong and guide me.