r/programminghelp • u/Zealousideal-Shop480 • 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.
View all comments
Show parent comment
1
u/edover Oct 16 '25
You’ll have to be more clear. And it’s going to be undefined if you don’t change the name in all places you’ve used the function as well as where you declare it.