ok I am continuing on with my evolving program
I have 2 structures and
what the program is doing is first finding the area of a rectangle "r"
then we are to find the center of that rectangle.
I worked a bit , think I got the point that is the center.
Now I have code here, but it isn't compiling right. I am to return as a value from the point structure. But how? I figured I'd return the value of that point's x, y coordinates (x and y axis on graph, of course)
but my return value is wrong.
Please help.
PHP Code:
#include <stdio.h>
struct point {
int x, y;
};
struct rectangle {
struct point upper_left, lower_right;
} r;
int area_of_r(struct rectangle rect);
int center_of_r(struct rectangle x,struct rectangle y);
int main(void) {
printf( "input upper left corner of rectangle r "
"as 0 0, with space in between.\n\n");
scanf( "%d %d", &r.upper_left.x, &r.upper_left.y );
printf( "input lower right corner of rectangle r "
"as 0 0, with space in between.\n\n");
scanf( "%d %d", &r.lower_right.x, &r.lower_right.y );
/* here we print the area of the rectangle */
printf( "\nThe area of rectangle r is "
"%d\n", area_of_r(r));
/* here we print the center of rectangle */
printf("\nThe center point of rectangle r is "
"%d %d",center_of_r(r));
return 0;
}
int area_of_r ( struct rectangle rect )
{
int area;
area = (r.lower_right.x - r.upper_left.x) *
(r.upper_left.y - r.lower_right.y);
return area;
}
int center_of_r(struct rectangle x, struct rectangle y)
{
int center;
int new_x, new_y;
/* having problems with this part, don't know how to run
line of assignments to next line...is that possible */
x = (r.lower_right.x -((r.lower_right.x -
r.upper_left.x)/2);
y = (r.upper_left.y - ((r.upper_left.y -
r.lower_right.y)/2);
/* here's the return call, but what is wrong here?? How
do I return the values of x and y which are the values
of the coordinates of a point on a graph ??? */
return (x,y);
}