-HOW IT WORKS-

When the loop first starts 'k' is 0 so when the cout statement executes it's like coding "cout<<ages[0] <<endl;" 'k' then increments by one and 'k' now equals 1 so now the cout statement looks like this "cout<<ages[1]<<endl;"...etc

max=my_array[0];//assign max a value to avoid garbage

Here is a part that seems weird at first but it's absolutely necessary! Our variable that is going to hold the highest value is 'max', in this specific loop it is going to be compared to 10 values to check whether or not they are higher than 'max' well if we don't assign max a value it will hold garbage. Remember garbage can be any number typically a ridiculous one. So say we didn't assign 'max' a value and allowed it to hold garbage and say in this case the garbage value was 5,250. Now say that when the user is finished inputing all 10 values that the highest value they entered in 'my_array' is 1,200. When the if condition checks to see if 'max' is less than 'my_array[k]' it will never happen. The highest value in 'my_array' is 1,200 but 'max' has the value of 5,250, in what world is 5,250 less than 1,200? Not this one. So if we assign 'max' the value of the first array 'my_array[0]' like we did above, we are ensuring that 'max' will never be higher than the highest value inside the data set in this case 'my_array'.

for (k=0; k<10; k++)
{
//if 'max' is less than my_array[k] then assign it that value
if (max < my_array[k])
{
max=my_array[k];
}
}

The next for loop is what actually cotains the algorithm used with an if condition. In this case it will run 10 times each loop checking to see if 'max' is less than 'my_array[k]' if it is less than, then 'max' will be assigned the value of 'my_array[k]' if it is not then nothing will happen. After the loop has ran 10 times and checked all 10 values 'max' is left with the maximum value of the data set.