Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Multi choice calculator script returns before answering result =/

Posted on 2014-01-21
Medium Priority
195 Views
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
Question by:stellarsystems
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 48

Accepted Solution

Tintin earned 2000 total points
ID: 39799193

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

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

LVL 1

Author Comment

ID: 39799223
Thank you so much, iv been looking at this all day asking myself what is wrong..
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
###### Suggested Courses
Course of the Month9 days, 11 hours left to enroll