Hi there,
I'm new to this forum and new to C++ programming and I've come across a problem.
I have a function that receives values for its arguments from an array. There are four argument for this function: up, down, left, right. Up is a value 1 greater than the current y value of the array. Down is a value 1 less than the current y value of the array. Left is a value 1 less than the current x value of the array. And right is a value 1 greater than the current x value of the array. The function then takes these four values and adds them together and divides by four, in order to calculate the average value. It then assigns this value to the current x, y array cell.
My problem is that when the array is sent a value of up (which is 1 above the current cell) and the current cell is at array[0][x] there is no value in that cell because it does not exist. This is also the case with the left, right, and down arguments, except along different edges of the array.
I was wondering if there was a way to assign a value of zero to only the arguments that are undefined.
Thank you very much for you time and I'm sorry for any poor use of terminology, I'm just learning. I also apologize if this question has been asked before, as I'm sure it has. But because I'm unsure of the proper terminology for some of what I'm asking, I don't know how to properly search for it.
Again thank you very much!
-Scott
A few lines of code can sometimes replace a thousand words. Or to put it another way - it might be easier to understand what you're asking for with some example code.
If your problem is to do with overflowing bounds of your array, then one simple solution is to pass in a separate argument which indicates the size of your array - you can then write some validation code to make sure that your indexes never exceed a value of size - 1 or drop beneath zero