Solved

Multi choice calculator script returns before answering result =/

Posted on 2014-01-21
2
180 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
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
Comment Utility
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
Comment Utility
Thank you so much, iv been looking at this all day asking myself what is wrong..
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Utilizing an array to gracefully append to a list of EmailAddresses
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 this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now