• Status: Solved
• Priority: Medium
• Security: Public
• Views: 207

# Multi choice calculator script returns before answering result =/

Hi Guys,

Can anyone help me with what im missing here?
It seems to calculate the result but instead of displaying like i want it too it loops back to the start.

Any hints would be greatly appreciated.

``````#/bin/sh

echo " \"Welcome\" to the most awsome calc evar"
echo "2) Subtract"	#subtract two numbers
echo "3) Multiply"	#multiply two numbers
echo "4) Divide"	#divide two numbers
echo "5) Factorial"	#Factorial two numbers
echo "6) Campare"	#Campare two numbers
echo "7) EXIT"		#exit the calculator
read CAL			#get number for selection on CALC
while [ \$CAL != 7 ]
#if CAL = to 7 will exit, if not continue next line
do
case \$CAL in			#database arrays
"1")
echo "Choose a number"
echo "Choose a another number to add to the first number"
VALUE=\$((\$NUM2+\$NUM1))
;;
"2")	echo "You've picked Subtract"
echo "Choose a number"
echo "Choose a another number to Subtract to the first number"
VALUE=\$((\$NUM1-\$NUM2))
;;
"3")	echo "You've picked Multiply"
echo "Choose a number"
echo "Choose a another to multiply"
VALUE=\$((\$NUM1*\$NUM2))
;;
"4")	echo "You've picked Divide"
echo "Choose a number"
echo "Choose a another to divide the first number"
VALUE=\$((\$NUM1/\$NUM2))
;;
"5")    echo "You've picked Factorial"
read NUM	# get a number
FOR=1
FOR=\$((\$FOR*\$NUM))	# FOR TIME NUM
NUM=\$((\$NUM-1))		# TAKE 1 OFF NUM
FOR=\$((\$FOR*\$NUM))	#FOR TIMES WITH NUM
NUM=\$((\$NUM-1))		#TAKE 1 OFF NUM
while [ \$NUM -gt 1 ]	# LOOP UNTIL NUM = 1
do
FOR=\$((\$FOR*\$NUM))
#times End by nu
NUM=\$((\$NUM-1))
#takes 1 off NUM
done
echo "And the answer is \$FOR"

;;
"6") 	echo "You've picked Compare"
echo "Pick a number"			#ask number
echo "Pick another number"
if [ \$NUM1 -eq \$NUM2 ]		#if NUM1 = NUM2
then
echo "First Number is equal to Second Number"	#show anwser NUM1=NUM2
else			#or
if [ \$NUM1 -lt \$NUM2 ]		#NUM1 less less than NUM2
then
echo "First Number is less then the Second Number"		#show answer A less B
else
echo "First Number is Greater than Second Number"			#or answer is A is Greater than B
fi
fi
;;
*)

echo "YOU ENTERED INVAILD OPTIONS"
;;

echo \$VALUE

clear
#space
echo "\"Welcome\" to the Magic CALC"
echo "2) Subtract"	#subtract two numbers
echo "3) Multiply"	#multiply two numbers
echo "4) Divide"	#divide two numbers
echo "5) Factorial"	#Factorial two numbers
echo "6) Campare"	#Campare two numbers
echo "7) EXIT"		#exit the calculator
read CAL	       #get number for selection on CALC
done
``````
0
stellarsystems
1 Solution

Commented:

So after line 86 where you do  echo \$VALUE, add

``````read -p "Press Enter to continue..."
``````
0

Author Commented:
Thank you so much, iv been looking at this all day asking myself what is wrong..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.