April 2nd, 2013, 11:59 PM

Finding the Average
Going to print my script here as a start
count=0
count2=0
total=0
for factor in $*
do
count=$( echo "$factor"  grep "^[09]*$"  wc l )
count2=$( echo "$factor"  grep "^[+][09]*$"  wc l )
if [ "$count" eq 1 o "$count2" eq 1 ]
then total=$(( total + $factor))
else
echo
echo " '$factor' is not numeric. Factor is ignored."
echo
fi
done
echo " Result = $total"
exit 0
The goal of the program is that the user can enter in as many integers as possible, entering a noninteger unit will be ignored, and the integers are then added together for the 'total' variable. THEN, the total is divided by the amount of integers entered giving me the average.
Currently the program only works with the addition and it only displays the total.
What I am stuck on is.... How do I get the script to recognize HOW MANY integers were entered in order to know how much to divide from the total amount.
Any help would be appreciated.
April 3rd, 2013, 02:05 PM

Originally Posted by Gogandantes919
What I am stuck on is.... How do I get the script to recognize HOW MANY integers were entered in order to know how much to divide from the total amount.
Perhaps you could count them?