Need some help with if statements

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 29
Reputation: Shinedevil is an unknown quantity at this point 
Solved Threads: 0
Shinedevil Shinedevil is offline Offline
Light Poster

Need some help with if statements

 
0
  #1
Nov 1st, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 480
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 56
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training
 
0
  #2
Nov 1st, 2009
you can easily perform a test on an entire range of values:
  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 39
Reputation: niXman is an unknown quantity at this point 
Solved Threads: 10
niXman's Avatar
niXman niXman is offline Offline
Light Poster
 
0
  #3
Nov 1st, 2009
  1. if ( x > 0 && x <= 380 ) {
  2. }
like this?
Я из Молдавии. Говорю на Русском.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: Shinedevil is an unknown quantity at this point 
Solved Threads: 0
Shinedevil Shinedevil is offline Offline
Light Poster
 
0
  #4
Nov 1st, 2009
Thanks so much, I probably would have found that out eventually. I don't know what was going through my mind...

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 480
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 56
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training

trick-or-code

 
0
  #5
Nov 1st, 2009
I think your mind was still focused on that Halloween candy.
Last edited by Clinton Portis; Nov 1st, 2009 at 1:27 am.
Reply With Quote Quick reply to this message  
Reply

Tags
c++

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for c++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC