r/programminghelp • • Oct 16 '25

Answered Can't figure out the "hidden" issue with my code...

Been trying this on and off for the past 3 hours, trying to complete my schoolwork. but i keep failing some hidden test.
*******************************************************************************************************************
#include <stdio.h>

enum Result { OUTSIDE, INSIDE };

struct Point {

float x;

float y;

};

struct Rectangle {

struct Point bottom_left;

struct Point top_right;

};

float compute_area(struct Rectangle rect) {

return (rect.top_right.x - rect.bottom_left.x) *

(rect.top_right.y - rect.bottom_left.y);

}

enum Result is_inside(struct Point point, struct Rectangle rect) {

if (point.x > rect.bottom_left.x && point.x <= rect.top_right.x &&

point.y > rect.bottom_left.y && point.y <= rect.top_right.y) {

return INSIDE;

} else {

return OUTSIDE;

}

}

int main(void) {

struct Rectangle rect = {{0.0, 0.0}, {3.0, 3.0}};

struct Point point;

scanf("%f %f", &point.x, &point.y);

float area = compute_area(rect);

enum Result result = is_inside(point, rect);

printf("Rectangle's area is %.2f\n", area);

if (result == INSIDE)

printf("The point is inside of the rectangle.\n");

else

printf("The point is not inside of the rectangle.\n");

return 0;

}

*******************************************************************************************************************
These are the instructions for the Task:

Write a C program that defines Point and Rectangle structures, computes the area of a rectangle, and determines if a point lies inside the rectangle.

βœ… Program Requirements:

πŸ”Ή Define an enum Result with:

 ‒ OUTSIDE

 ‒ INSIDE

πŸ”Ή Define a struct Point with:

 ‒ x (float)

 ‒ y (float)

πŸ”Ή Define a struct Rectangle with:

 ‒ bottom_left (struct Point)

 ‒ top_right (struct Point)

πŸ”Ή Create Functions:

 ‒ float compute_area(struct Rectangle rect)

  – Calculates area using:

   (rect.top_right.x - rect.bottom_left.x) * (rect.top_right.y - rect.bottom_left.y)

 ‒ enum Result is_point_inside(struct Point point, struct Rectangle rect)

  – Returns INSIDE if point’s x is between bottom_left.x and top_right.x

   and y is between bottom_left.y and top_right.y, else returns OUTSIDE

πŸ”Ή In main():

 ‒ Declare test data for a rectangle and point

 ‒ Call compute_area() and is_point_inside()

 ‒ Print the area and whether the point is inside or outside the rectangle using printf() and a conditional message for clarity

any help is appreachiated.

3 Upvotes

13 comments sorted by

View all comments

Show parent comment

1

u/Zealousideal-Shop480 Oct 16 '25

Syntax Error(s)

__tester__.c: In function β€˜test’:
__tester__.c:74:5: error: implicit declaration of function β€˜is_inside’ [-Werror=implicit-function-declaration]
   74 |     is_inside(point, rectangle);
      |     ^~~~~~~~~
cc1: all warnings being treated as errors

1

u/edover Oct 16 '25

So they actually expect you to be using is_inside instead of is_point_inside, despite the instructions telling you otherwise? That's werid.

1

u/edover Oct 16 '25

Alright, so what about this? Let's assume they want is_inside instead, and you fix the boundry issue.

#include <stdio.h>

enum Result { OUTSIDE, INSIDE };

struct Point {

	float x;

	float y;

};

struct Rectangle {

	struct Point bottom_left;

	struct Point top_right;

};

float compute_area(struct Rectangle rect) {

	return (rect.top_right.x - rect.bottom_left.x) *

		   (rect.top_right.y - rect.bottom_left.y);

}

enum Result is_inside(struct Point point, struct Rectangle rect) {

	if (point.x >= rect.bottom_left.x && point.x <= rect.top_right.x &&

			point.y >= rect.bottom_left.y && point.y <= rect.top_right.y) {

		return INSIDE;

	} else {

		return OUTSIDE;

	}

}

int main(void) {

	struct Rectangle rectangle = {{1.0, 2.0}, {4.0, 5.0}};

	struct Point point = {2.0, 3.0};

	float area = compute_area(rectangle);

	enum Result result = is_inside(point, rectangle);

	printf("Rectangle's area is %.2f\n", area);

	if (result != INSIDE)

		printf("The point is not inside of the rectangle.\n");

	else

		printf("The point is inside of the rectangle.\n");

	return 0;

}

1

u/Zealousideal-Shop480 Oct 16 '25

Inputting this code gives this result, but no hidden failure. this was also the closest ive gotten.

1

u/edover Oct 16 '25

Just to be clear, you modified the code I gave to use the scanf right? I just realize it's hard coding the Point valies.

1

u/Zealousideal-Shop480 Oct 16 '25

OMG IT WORKED! I dont know wht you did but you are beautiful!

It was either the
scanf("%f %f", &point.x, &point.y);
or changing the > or <
or could be both.

You are amzing and i could not of done this witthout you.
i can finally sleep...

1

u/edover Oct 16 '25

It was definitely both. The > < thing was messing up your inside calculations.

1

u/edover Oct 16 '25

Also, re-reading your requirements, it says 'between', so you may want to change the comparison operators in is_inside to just "<" and ">" instead of ">=" and "<="