Click to See Complete Forum and Search --> : Count elements within bounds in 2D array
Will16
November 24th, 2006, 09:13 AM
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
AlbertGM
November 24th, 2006, 09:25 AM
And what's the problem doing what you said?
//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.
SuperKoko
November 24th, 2006, 09:51 AM
And what's the problem doing what you said?
//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:
20<=i && i<=40 && 100<=j && j<=300
AlbertGM
November 24th, 2006, 10:03 AM
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.
SuperKoko
November 24th, 2006, 10:19 AM
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.
:)
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.
AlbertGM
November 24th, 2006, 10:36 AM
Please, continue posting.
Of course I'll do. I'm learning a lot :-)
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.
SuperKoko
November 24th, 2006, 01:18 PM
How I blocked that?
I guess it is the default behavior.
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/profile.php?do=editoptions
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.