944,139 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 418
  • C++ RSS
Nov 1st, 2009
0

Need some help with if statements

Expand Post »
I need to have a function like this:
if (x == 1){
...
}
do some amazing things.

I need it to check to see if x == 1 through 380 or more.
But I really don't want to waste 4 hours doing this:
if (x == 1 || x == 2 || x == 3 || ... || x == 380)

I am using a mouse peripheral and I need it to check to see if the mouse x/y coords are, when clicked, in a certian place on the screen. So essentially "x == 1" is the #1 pixel on the x coords.

If someone can help me find a way to do this faster, THANKS!
Reputation Points: 8
Solved Threads: 4
Junior Poster in Training
Shinedevil is offline Offline
71 posts
since Nov 2008
Nov 1st, 2009
0
Re: Need some help with if statements
you can easily perform a test on an entire range of values:
C++ Syntax (Toggle Plain Text)
  1. //If 'x' is greater than or equal to 1 AND 'x' is less than or equal to 380
  2. if(x >= 1 && x <= 380)
  3. {
  4. //Do amazing things
  5. }
Last edited by Clinton Portis; Nov 1st, 2009 at 1:04 am.
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Clinton Portis is offline Offline
822 posts
since Oct 2005
Nov 1st, 2009
0
Re: Need some help with if statements
C++ Syntax (Toggle Plain Text)
  1. if ( x > 0 && x <= 380 ) {
  2. }
like this?
Reputation Points: 10
Solved Threads: 10
Light Poster
niXman is offline Offline
39 posts
since Oct 2009
Nov 1st, 2009
0
Re: Need some help with if statements
Thanks so much, I probably would have found that out eventually. I don't know what was going through my mind...

Thanks.
Reputation Points: 8
Solved Threads: 4
Junior Poster in Training
Shinedevil is offline Offline
71 posts
since Nov 2008
Nov 1st, 2009
0

trick-or-code

I think your mind was still focused on that Halloween candy.
Last edited by Clinton Portis; Nov 1st, 2009 at 1:27 am.
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Clinton Portis is offline Offline
822 posts
since Oct 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Finding Struct highest and lowest!
Next Thread in C++ Forum Timeline: Game of Crap





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC