Count elements within bounds in 2D array
Hi,
I'm trying to count the number of elements that contain numbers that lie within two boundry conditions in a 2D array.
So, if I have my data:
i j
10 100
20 200
30 300
40 400
I want to know how many rows (20<=i<=40 && 100<=j<=300). In this case 2. The arrays are also many lines long.
I thought that this would be really easy to do in a language that seems as powerfula nd flexible as C++ but......
Any ideas. Cheers.
Will
Re: Count elements within bounds in 2D array
And what's the problem doing what you said?
Code:
//for each 2D number
if(20<=i<=40 && 100<=j<=300)
//value is within
else
//it's not
I think I don't undestand your problem!! Sorry!
Albert.
Re: Count elements within bounds in 2D array
Quote:
Originally Posted by AlbertGM
And what's the problem doing what you said?
Code:
//for each 2D number
if(20<=i<=40 && 100<=j<=300)
//value is within
else
//it's not
I think I don't undestand your problem!! Sorry!
Albert.
20<=i<=40 yields true whatever i is. It is interpreted as (20<=i)<=40
Same thing for 100<=j<=300
The correct condition is:
Code:
20<=i && i<=40 && 100<=j && j<=300
Re: Count elements within bounds in 2D array
SuperKoko, you are always correcting me. I think I won't do any any other post, because all of them have errors :-)
Thanks for your answers and for correct me. It could be because today I've lunch with wine :-)
Albert.
Re: Count elements within bounds in 2D array
Quote:
Originally Posted by AlbertGM
SuperKoko, you are always correcting me. I think I won't do any any other post, because all of them have errors :-)
Please, continue posting.
Doing errors in untested code is very usual. Personally, I can't write much code without any problem if I don't try to compile it.
With time, you'll do fewer errors on untested code.
:)
Quote:
Originally Posted by AlbertGM
Thanks for your answers and for correct me. It could be because today I've lunch with wine :-)
It may be a factor. :)
Personally, I do many more errors when I'm sleepy.
PS: I tried to send this message as a PM but AlbertGM blocked PMs in his account.
Re: Count elements within bounds in 2D array
Quote:
Originally Posted by SuperKoko
Please, continue posting.
Of course I'll do. I'm learning a lot :-)
Quote:
Originally Posted by SuperKoko
PS: I tried to send this message as a PM but AlbertGM blocked PMs in his account.
What's that? How I blocked that? How Can I unlock it?
Albert.
Re: Count elements within bounds in 2D array
Quote:
Originally Posted by AlbertGM
How I blocked that?
I guess it is the default behavior.
Quote:
Originally Posted by AlbertGM
How Can I unlock it?
Go to the User CP page, click the User Options link, and then, activate "Enable Private Messaging", and finally, click "Save Changes".
This link should go to your user options page:
http://www.codeguru.com/forum/profil...do=editoptions