0 is smaller than any of your numbers in file, so you should initialize minVal to inputArray[0] and start for from i=1.
pyTony
pyMod
6,330 posts since Apr 2010
Reputation Points: 879
Solved Threads: 989
Skill Endorsements: 27
Question Answered as of 1 Year Ago by
pyTony A better solution is to count up how many values you're putting into your array. For instance, what if the lowest value was zero? What if you have no idea what the lowest value might be in the data?
The better logic is:
1) count the number of values you are putting into your array, and loop ONLY through those values. 30 Values read in? Then you'll search from array[0] to array[29], only.
2) set the initial minimum value to the first value you put into your array. If the value is 100, and there are lesser values in the data, that's OK. Because you'll have an if() statement inside the loop:
if(newValue is < minimumValue)
minimumValue = newValue;
and you have the minimum value as soon as you've read in all the newValues, and made this comparison.
It's fast, (no dealing with irrelevant array values (lots of zeroes), clear, and accurate.
Adak
Posting Virtuoso
1,641 posts since Jun 2008
Reputation Points: 456
Solved Threads: 196
Skill Endorsements: 7