Hi,
I'm trying to create a memory game based on colours. I wrote this code and BricxCC compiles it but when i run it in my NXT ti shows a file error:
the code is this:
That type of error is often something out of range. (bad parameter)
I believe arrays in NXC are 0-based, so the statement:
int random[4];
creates four elements, numbered 0-3. Looks like changing the statements to:
int random[5];
...should solve the problem. However, keep in mind that you've created an array that is larger than what you need. That's generally not a good programming technique.
Steve
---> Link to lots of MINDSTORMS stuff under my picture --->
hassenplug wrote:...should solve the problem. However, keep in mind that you've created an array that is larger than what you need. That's generally not a good programming technique.
I would also replace "4" with a #define constant named ARRAY_SIZE or something like that so that you do not have what are referred to as "magic numbers" sprinkled throughout your source code. Alternatively, you could call ArrayLen instead of using a hard-coded value.
Forgot to mention that you would also need to start i and j counting at zero instead of 1 and use < rather than <= in the for loops that iterate on i and j.