Sometimes it helps just to think through it out loud. You don't say what type your variable "Vin" is but if it's an integer you might want to make it an unsigned int as it could, theoretically, get larger than a regular int.

Yah! You're right

About Vin, I declared it as a double

Temp is also a double!

About variable "samples[50]"... each sample is an integer [0 - 1023].

However, adding 50 integers and then divide all by 50 the "samples" variable could NOT be an integer.

That is, if all samples are 500 (ADC). Then the sum is 50*500 = 25000. Then, dividing all by 50, the average value is 500!!! OK, it's an integer!

But if 49 samples are 500 (ADC). and the last one is 501. The average value is 500.02

If "samples[50]" is declared as a integer, it would be rounded down to 500. But the real value is 500.02.

So, I also declared it as a double!

Thank you so much for your help!

Regards.