First, your error message is pretty clear about what is happening, you are trying to access an element of an array out of the range of the array.
For example if you have an array from zero to n,...