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
2
Medium Priority
?
195 Views
Last Modified: 2014-01-21
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 "1) Addition"	#add two Numbers
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 "You've picked Additions"
	echo "Choose a number"
	read NUM1
	echo "Choose a another number to add to the first number"
	read NUM2
	VALUE=$(($NUM2+$NUM1))
	;;
"2")	echo "You've picked Subtract"
	echo "Choose a number"
	read NUM1
	echo "Choose a another number to Subtract to the first number"
	read NUM2
	VALUE=$(($NUM1-$NUM2))
	;;
"3")	echo "You've picked Multiply"
	echo "Choose a number"
	read NUM1
	echo "Choose a another to multiply"
	read NUM2
	VALUE=$(($NUM1*$NUM2))
	;;
"4")	echo "You've picked Divide"
	echo "Choose a number"
	read NUM1
	echo "Choose a another to divide the first number"
	read NUM2
	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
	read NUM1			#ask another number
	echo "Pick another number"
	read NUM2
	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 "PLEASE TRY AGAIN"
	;;
esac				#show answer

echo $VALUE

clear		
		#space
echo "\"Welcome\" to the Magic CALC"
echo "1) Addition"	#add two Numbers
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

Open in new window

0
Comment
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
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 39799193
You just need to add a pause after displaying the answer.

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

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

Open in new window

0
 
LVL 1

Author Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question