I'm going through some practice for arrays (let me specify this is NOT homework i just completed a test which i know in my soul i failed and i'm practicing) and performing functions on them and I'm running into this problem. My method for finding highest number, average, and total works but, find the lowest number isn't and I'm honestly stuck as to why.
To explain my array: index 0 is where i want to store my highest number index 1 is where i want to store my lowest number
my method starts at index 2 to find lowest / highest numbers since the lowest / highest would be store in the first two element of the array. my array size also takes this into concideration as well as the file reader, they all start at index 2.
I've also tried value returning methods while still getting the same end result.
Below are the methods i've tried that aren't putting out the desired information:
this method assigns highest to salesArray[0] and lowest to salesArray
CodePudding user response:
Arrays are indexed starting at 0, not 1. Also, be careful when you access to element at position 1, it will crash for arrays with size less than 2.
CodePudding user response:
the problem was found in trying to use two variables for highest/lowest and changing the array size and read count for it.
after changing first initialization for index to 0 and making highest/lowest index 0 it is now working.
Thanks for all the help that help lead me here.