Ok, I have everything completed finally but I'm getting one last problem with the function. For some reason when it runs the 'p_evaluation' function, and I input the points to be tested equal to one of the points provided in 'upper_left' or 'lower_right' it returns FALSE. This is a point on the graph of the rectangle and it seems like my condition I have made would make this true. Any suggestions?
Code:
#include <stdio.h>
#include <string.h>
struct point { float x, y;} center, units, p;
struct rectangle { struct point upper_left, lower_right;} r;
float area_of_r(struct rectangle rect);
float center_of_r(struct rectangle rect);
float move_units(struct rectangle rect);
int p_evaluation(struct rectangle rect);
int main() {
char condition[6];
int i;
printf( "Input upper left corner of r : " );
scanf( "%f %f", &r.upper_left.x, &r.upper_left.y );
printf( "Input lower right corner of r : " );
scanf( "%f %f", &r.lower_right.x, &r.lower_right.y );
printf( "Area of r is %.2f\n", area_of_r(r) );
center_of_r(r);
printf( "The center of r is ( %.2f, %.2f )\n", center.x, center.y);
move_units(r);
i = p_evaluation(r);
if(i == 1)
strcpy(condition, "TRUE");
else
strcpy(condition, "FALSE");
printf("\nThe point p evaluation returned: %s\n", condition);
return 0;
}
float area_of_r ( struct rectangle rect ) {
float area=0;
area = (rect.lower_right.x - rect.upper_left.x )*( rect.upper_left.y - rect.lower_right.y);
return area;
}
float center_of_r(struct rectangle rect) {
center.x = (rect.upper_left.x + rect.lower_right.x)/2;
center.y = (rect.upper_left.y + rect.lower_right.y)/2;
}
float move_units(struct rectangle rect) {
printf("Type the number of units to move the rectangle: ");
scanf("%f %f", &units.x, &units.y);
printf("\nThe modified points of the rectangle are: \nUpper left: ( %.2f, %.2f ) \nLower right: ( %.2f, %.2f)\n"
, rect.upper_left.x + units.x, rect.upper_left.y + units.y,
rect.lower_right.x + units.x, rect.lower_right.y + units.y);
}
int p_evaluation(struct rectangle rect) {
int i=0, j=1;
printf("Type a point to test if it is within the rectangle: ");
scanf("%f %f", &p.x, &p.y);
if(rect.upper_left.x <= p.x <= rect.lower_right.x && rect.upper_left.y >= p.y >= rect.lower_right.y)
return j;
else
return i;
}