# Thread: Struct Program to find Point in Rectangle

1. ## Struct Program to find Point in Rectangle

I am working on an assignment where I have to create a program for users to input coordinates for a rectangle.

This program is intended to be a struct within a struct.

If invalid, I have to output an error message and let user try again, indefinitely, until the user gets it right.

The program should repeatedly ask users for coordinates of a point, and the program will quit when user enters 0 and 0 for x and y respectively.

The program has to say whether the point is inside of outside the rectangle. I also need to figure out where to put the main function, and what to put in it. Please let me know how exactly to complete this program, and I need to know ASAP. The program is due TONIGHT.

Here is my code:

Code:
```#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>

typedef struct
{
int x;
int y;
} point_t;

typedef struct
{
point_t upper_left;
point_t lower_right;
} rectangle_t;

int is_inside (point_t* pPoint, rectangle_t* pRect)
{
return ((pPoint->x >= pRect->upper_left.x ) &&
(pPoint->x <= pRect->lower_right.x) &&
(pPoint->y >= pRect->upper_left.y ) &&
(pPoint->y <= pRect->lower_right.y));

}

point_t get_point(char* prompt)
{
point_t pt;
printf("Given a rectangle with a side parallel to the x axis and a series of points on the xy plane this program will say where each point lies in relation to the rectangle. It considers a point on the boundary of the rectangle to be inside the rectangle\n");
printf ("Enter coordinates for the upper left corner\n");
printf ("X: ");
scanf ("%d", &pt.x);
printf ("Y: ");
scanf ("%d", &pt.y);

return pt;
}

rectangle_t get_rect(char* prompt)
{
rectangle_t rect;
printf (prompt);
rect.upper_left = get_point("Upper left corner: \n");
rect.lower_right = get_point("Lower right corner: \n");

return rect;
}``` 2. Originally Posted by DMJKobam I also need to figure out where to put the main function...
After the function definitions... Originally Posted by DMJKobam ...and what to put in it.
Function calls...

It looks like most of the work is done, and you just have to call the functions. I suspect these functions were already provided for you, and you just had to create main. If you have problems writing main, post what you've done and someone could probably help. However, it seems you didn't leave yourself enough time for this. 3. ## Functions where not provided

The functions where not provided. I am trying to figure out to how to call them. I have to submit this in an hour. Popular pages Recent additions 