help please


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help please
# 1  
Old 04-22-2006
help please

I need to multiply a number , howeveri am aware that there is a command to extend the variable? ,currently if my total goes over 250 my answer is wrong, script as below . thank you


mulfunc ()

{
# if the entered number is 0 or less , then answer 0
if [ $1 -le 0 ]

then
return 0
# otherwise X this by 100
else
RESULT=`expr $1 \* 10`

return $RESULT


fi
}
echo "the total is /n"

read TOTFAC
#call the function to perform calculation
mulfunc $TOTFAC
echo "the income from $TOTFAC is $? pounds
"
# 2  
Old 04-22-2006
The return code is intended only for success/failure. Do it this way:

mulfunc ()

{
# if the entered number is 0 or less , then answer 0
if [ $1 -le 0 ]

then
echo 0
return 0
# otherwise X this by 100
else
RESULT=`expr $1 \* 10`

echo $RESULT
return 0


fi
}
echo "the total is /n"

read TOTFAC
#call the function to perform calculation
ans=`mulfunc $TOTFAC`
echo "the income from $TOTFAC is $ans pounds
"
# 3  
Old 04-22-2006
thanks for such a quick reply
i've tried the script , and unfortunetly it doesn't return any answer ?
# 4  
Old 04-22-2006
I apologise i've found MY mistake - many thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question