Hi, I'm trying to find average of an array using function. But the average should be 5.5, instead it shows 5.00. I don't know if anything wrong with my code. Thank you.
int Array[10] = { 8, 7, 6, 3, 2, 1, 5, 4, 9, 10 };
double Result;
double avg;
double ArrayAverage(int sum) {
Result = sum/10;
return Result;
}
void setup() {
Serial.begin(9600);
int sum=0;
for (int index=0; index<=9; index++) {
sum = sum + Array[index];
}
Result = ArrayAverage(sum);
Serial.print("Result: ");
Serial.print(Result);
}
void loop() {
}