One easy way to avoid integer division is to define the running total (i.e., the accumulator) variable as a double
. Although the user enters integers, the program automatically converts or promotes them to doubles before adding them to the running total. Alternatively, you can also write the last statement as return (double)sum / 10;