Shell Script not working using for loop and a funtion

Hi-

Here is the shell script that for some reason is not returning results:

#! /bin/ksh -

avg()   {
        AVG=0
        typeset SUM=0
        if [ "$#" -lt 2 ]
        then
                echo "You must have at least two numbers"
        else
        for NUM in "$*"
        do
                SUM=$(( SUM + $NUM ))
                echo "SUM: $SUM + $NUM"
        done
                AVG=`echo "scale=2; $SUM/$#"|bc`
        fi
}

ANS=$(avg $*)
echo "Average of $@ is $ANS"

If you run it would simply say "Average of numbers (list the numbers) is"
and give me this error

"./avg.sh: line 13:  SUM + 5 2 : arithmetic syntax error"

Thanks

don't quote the $*
and you should return the $AVG instead the "SUM: $SUM + $NUM"

try:

avg()   {
        AVG=0
        typeset SUM=0
        if [ "$#" -lt 2 ]
        then
                echo "You must have at least two numbers"
        else
        for NUM in $*
        do
                SUM=$(( SUM + $NUM ))
                #echo "SUM: $SUM + $NUM"
        done
                AVG=`echo "scale=2; $SUM/$#"|bc`
                echo $AVG
        fi
}

ANS=$(avg $*)
echo "Average of $@ is $ANS"

Yes, it worked. Thanks for your help.