I'm trying to write a program that can compute the average result given an integer N
#!/bin/sh
CTR=0
sum=0
read N
while [ $CTR -ne $N ]; do
read integer;
sum=$(( $integer + $sum ))
CTR=$(( $CTR + 1 ))
done
printf '%.3f\n' "$(( $sum * 1/ $N ))"
This was my input when compiling :
2
5
6
Expected output 5.500
Actual output 5.000
Why is that ?
float sum N
, then the rest of the script should work as written. – glenn jackman Dec 22 '20 at 01:17