Do you know how to pass back using *r ? As using a direct printf in the function, the w*h is working and calculating it correctly, but when it is printed out in the main function, it seems that it is not tabulated and passed back the correct value of w*h. I need to return *r and print out *r. I tried by "return (*r) or return (&r), but it prompts me error. It stated "return : cannot convert from 'Rectangle' to 'double'.
Code:
printf("Enter top left point : ");
scanf("%lf",&r.topLeft.x);
scanf("%lf",&r.topLeft.y);
fflush(stdin);
printf("Enter bottom right point : ");
scanf("%lf",&r.botRight.x);
scanf("%lf",&r.botRight.y);
computeArea(&r);
printf("Rectangle Area : %lf",r);
double computeArea(Rectangle *r)
{
double h=0,w=0,z=0;
w=fabs(r->topLeft.x - r->botRight.x);
printf("w : %lf\n",w);
h=fabs(r->botRight.y - r->topLeft.y);
printf("h : %lf\n",h);
z=w*h;
printf("w*h : %lf\n",z);
return (z);
}