To get the average:
Initialize sum to zero before the for loop.
You want to add res to sum each time res is calculated. So you what to do that inside the for loop after the calculation of res.
After the loop divide by the total number of tanks gets you the average.
Like this.
Code:
Edit: removed code since
Leave a comment: