Data averaging fluctuation [SOLVED]

I did change the orientation of the lines of code, but I noticed that I also had to change:

-the variables declaration and initialisation (temp, average temp, total temp)
-sampling (a problem was that the nSample variable was printing up to 8 on the serial monitor and dividing the average by 9, which was rather confusing for a minute or two)
-whether the variable is static or not
-the location of the dtostrf functions

just for an example.

So it may have looked like all I had to do was change the operation of the code, but it was a little bit more than that, which was why I was a little stuck.

I do normally always isolate any code I need to debug, but I was cut short for time yesterday, as I'm also using this code for a job file for my college work.

Thank you!