This program is supposed to call the first function, read-series and then pass the input of every iteration of the while loop to the even-odds function which would tell if the number was even or odd and make VARSUMODDS=the value of VARSUMODDS+input if it was odd or make VARPRODUCTEVENS=the value of VARSUMEVENS*input. Then it would print them out. I'm sure there are a thousand syntax errors here, so please, be brutal. Keep in mind that I just started learning this language and I just came to it knowing only C++ and Java a few days ago, so don't expect me to understand complex answers. Thanks!
#! /bin/bash
TMPDIR=${HOME}/tmpdir
echo "Enter an integer: "
VARSUMODDS=0
VARPRODUCTEVENS=0
function read-series() {
while read numbers ; do
echo "Enter an integer: "
even-odds $numbers
done
echo numbers > $TMPDIR/$$.temp
return 0;
}
function even-odds() {
evenp=$(( $1 % 2 ))
if [ $evenp -eq 0 ] ; then
$VARPRODUCTEVENS=$(($VARPRODUCTEVENS * $1))
return 0;
else
$VARSUMODDS=$(($VARSUMODDS + $1))
return 1;
fi
}
function reduce () {
echo -n "Sum of odds: "
echo VARSUMODDS
echo -n "Product of evens: "
echo VARPRODUCTEVENS
return 0;
}
read-series