OK. I'll bet sourceforge.net has something you can use.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
ok maybe I didn't explain this right the array has a fixed amount of rows and columns. I am supposed to randomly populate the array with 12 objects
I wanted to identify the objects with a number such as 1. the user is then prompted to guess the location of the hidden objects.
First define your array, kinda like you did: int multi-d[rows][columns]
Then fill it with 0's with for loops.
Then loop from 1 to 12 and useLamaBot's idea with rand() to get a location in the array. Check if the location is zero. If so, load the loop value. If not, get another location.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
You know, LamaBot, you don't have to quote every post in their entirety if you aren't going to reference any part of it. And you can edit the quote down to only show the relevant portions you wish to comment on. That would help by not having a 200 line quote with a 3 line reply that has little to do with the quote. Just a thought... ;)
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
>>why are we defining elements
By that I assume you mean why intialize elements to some default value. Assuming that is correct, the answer is: when you declare an array none of the elements are initialized, just like when you declare a single element. Therefore, if you try to access any given element of an unitialized array to check it's value there is nothing you can check it against. So you initialize all the elements with a default value. Then when you go to enter the actual data you check to see if the value of any given element is the default value or not. If it is the default, then the space is open. It it isn't the default then the space is already occupied. If you have 12 elements assigned to random spots in the array there is always the possibility that you could end up overwriting one value with another if the same x and y values came up which would mean you have less than the desired elements actually occupied.
If you have a large array, then loops are a much easier way to initialize t he array, rather than initializing each element manually.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
LamaBot, please watch your formatting . We are trying to show by example. Poorly formatted examples tells the poster it's OK to be sloppy...
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944