In my project I have a string array filled with names. My main method asks the user to type in a name to search for. If the name is in the array it will say, "the name is found in the array." and how many comparisons it took to find that name within the array. Then vice versa if the name is not found. I need to also print out the average number of comparisons once the program ends, this being the sum of the comparisons divided by the number of searches.
I have a variable that keeps track of the number of searches, int numberOfSearches, and I have a variable, int comparisons, that is the comparisons for one search. Is there a way to have a variable, int totalComparisons, that is the sum of my comparisons?