Solved

Multi choice calculator script returns before answering result =/

Posted on 2014-01-21
2
181 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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 …
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

27 Experts available now in Live!

Get 1:1 Help Now