Archived

This topic is now archived and is closed to further replies.

advanced use of the IF statement

This topic is 5205 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey GDers! I have an extremely tedious task for you. I have an IF statement with a LOT of parentheses (29x2 pairs!). The problem is that my compiler (Borland C++ Builder 3) gives me errors ("Expression syntax", "If statement missing )" and "Compound statement missing }" ) Sound like a n00b problem? Perhaps it is and people use IF like this all the time, but is it possible to go overboard like I did here?
if( (
( (x1 <= x ) && (x2 => x) ) ||
( (x2 <= x) && (x1 => x) )
) && (
( (line->x1 <= x) && (line->x2 => x) ) ||
( (line->x2 <= x) && (line->x1 => x) )
) && (
( (y1 <= y) && (y2 => y) ) ||
( (y1 >= y) && (y2 <= y) )
) && (
( (line->y1 <= y) && (line->y2 >= y) ) ||
( (line->y1 >= y) && (line->y2 <= y) ) )
) {
return true;
}

This block of code checks that the bounds of x are within x1 and y1 and within line->x1 and line->x2, and that the bounds of y are within y1 and y2 and within line->y1 and line->y2. a) Is this a legal use of IF, and if so, why am I getting errors with it? b) Is there a simpler way of doing this? Cheers! Stay Clausal, Red Sodium

Share on other sites
sounds like you have a ")" that is missing somewhere.

Share on other sites
That''s the problem, I don''t. I have looked at my nested depths several times and they''re fine, AND when doing a search for "(" and ")" I get 29 each times. Certainly a weird problem...

Stay Clausal,

Red Sodium

Share on other sites
I checked with UltraEdit, and all your braces match. Maybe the problem is the places where you''re using => instead of >=. Sometimes the error message that''s given isn''t always an indication of what the real problem is.

Share on other sites
Take off the last ) and it should work

Share on other sites
Ahhh, it was the "=<" thing after all! I should''ve noticed that. Thanks everyone.

Stay Clausal,

Red Sodium

Share on other sites
I produced this:

if	( 		( 			(						(					x1 <= x 				) 				&& 				(					x2 => x				) 			) 			|| 			( 				(					x2 <= x				) 				&& 				(					x1 => x				) 			)		) 		&&		( 			( 				(					line->x1 <= x				) 				&& 				(					line->x2 => x				) 			) 			||            			( 				(					line->x2 <= x				) 				&& 				(					line->x1 => x				) 			)		)		&&		(			( 				(					y1 <= y				)				&&				(					y2 => y				) 			) 			||			(				(					y1 >= y				) 				&& 				(						y2 <= y				) 			)		) 		&& 		(			(				(					line->y1 <= y				)				&&				(					line->y2 >= y				)			) 		) 		||		( 			(				line->y1 >= y			) 			&&			(				line->y2 <= y			) 		)	)            ) //remove this one i think	{                return true;	};

edit: Damn what a waste of time, and I was wrong.

[edited by - honayboyz on April 15, 2004 7:04:15 PM]

Share on other sites
Red_Sodium, were you apart of Unga Bunga?

Share on other sites
No, but I''m a tester for Mission: Land!, Fusion Apple''s next game. Well, I helped out with a few things in Unga Bunga. I''m guessing you know this from the link my signature takes you to?

Stay Clausal,

Red Sodium

Share on other sites
quote:
Original post by red_sodium

b) Is there a simpler way of doing this?

If you could guarantee that x1 is always <= x2 (and same for the y's), then half of those cases would dissappear. You could always swap x1 and x2 to make it true.

You can break up the construction into some booleans to make it far more readable.

Here's my version of that thing:

bool within_x = ((x1 <= x ) && (x2 >= x)) || ( (x2 <= x) && (x1 >= x));bool within_y = ((y1 <= y ) && (y2 >= y)) || ( (y2 <= y) && (y1 >= y));bool within_line_x = ((line->x1 <= x ) && (line->x2 >= x)) || ( (line->x2 <= x) && (line->x1 >= x));bool within_line_y = ((line->y1 <= y ) && (line->y2 >= y)) || ( (line->y2 <= y) && (line->y1 >= y));return within_x && within_y && within_line_x && within_line_y;

[edited by - pinacolada on April 15, 2004 8:34:33 PM]

1. 1
2. 2
Rutin
24
3. 3
JoeJ
19
4. 4
5. 5
gaxio
13

• 17
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631729
• Total Posts
3001918
×