You never initialize the min* and max* variables so when you use them, you're getting junk.
I'd do it like this:
- Given the points of opposite corners, figure out the top, bottom, left and right edges of the rectangle.
- Do the same with the other rectangle. Since you're doing the same thing twice, make it a function.
To decide if rectangles overlap, it's easiest to figure out if they don't overlap first. Two rectangles A and B don't overlap if A is above, below, to the right, or to the left of B: A.bottom > B.top || A.top < B.bottom || A.right < B.left || A.left > B.right
And since they either overlap or they don't, just take the "not" of that value to determine if they overlap.
@dhayden
Thanks, for the help!
But, I don't think the problem is on initializing the min and max, because when i compile there is no error, but the solution is wrong , for ex. if i type the coordinates of 2 rectangles that overlap, the program writes "no overlap".
Also, how can i make it a function? I'm having difficulties at understanding how a function works.
I don't think the problem is on initializing the min and max, because when i compile there is no error,
Just because it compiles doesn't mean it will work. If you enable warnings when you compile, it will probably complain about the uninitialized variable.