The reason you're always getting 7 is because in the for loop in findHighest(), you're setting largestNumber to i, when you should set it to division_array[i]. i will always equal size-1 when the for loop has ended, so largest number will always equal size-1.
Another thing you need to address is that you're passing an array of doubles as an array of ints. divisonSales[] is a double, while your function, findHighest(int array[], size) calls for an int. This could cause extreme rounding errors (or a compiler error).
And finally:
1 2 3 4 5 6
|
divisionSales[0] = getSales(NORTHWEST);
divisionSales[1] = getSales(NORTHEAST);
divisionSales[2] = getSales(SOUTHWEST);
divisionSales[3] = getSales(SOUTHEAST);
findHighest(divisionSales[DIVISIONS], DIVISIONS); //DIVISIONS is not the size of the array at the moment.
|
You've only defined four members in divisionSales, not the max size. By passing DIVISIONS to that function, you're iterating over members of divisionSales that haven't been initialized (they inherit whatever random value is in the memory slot they're allocated.) It's possible that you could get some of these random, uninitialized values that are larger than anything you input, causing your function to yield incorrect results.
To fix this, you should pass the amount of
used slots in divisionSales as the size parameter, not it's maximum amount of slots.