Hello all, I appreciate you taking the time to look at this. Basically what I need to do for this is to input up to 100 integers into an array and stop when the user enters 0. Then I need to find the largest value the user entered into that array. I have the code to input values into the array and stop when the user enters 0 working just fine, and it is as follows:
for some reason, when I try to output the find_largest function, it is giving me a large, random number. I created a seperate file to test out the function to find the largest number in an array, and i have that working just fine aswell, it is as follows:
This function finds the largest value in the array with no problems, and this is the same function that I have in my main program. Why is this function returning the largest number in the array and the one in my main program returning a random number?
Basically what I need to do for this is to input up to 100 integers into an array and stop when the user enters 0.
The function compares the initial element to all of the elements within the array (if the second argument is the array's size). That is a problem if not all of the elements within the array have been assigned a value. If they have not been, the function is comparing the initial element to garbage values, which just happen to be larger than the values entered. That is where the 'random' value is coming from.
Initialize the count variable to zero and then pass it to the 'find_largest' function as the second argument to fix the problem.