Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Shell Script to make a menu driven calculator using case

Posted By: Samuel Evans     Category: Unix / Linux / Ubuntu     Views: 28274

Write a Shell Script to make a menu driven calculator using case.

Code for Shell Script to make a menu driven calculator using case in Unix / Linux / Ubuntu

clear
sum=0
i="y"

echo " Enter one no."
read n1
echo "Enter second no."
read n2
while [ $i = "y" ]
do
echo "1.Addition"
echo "2.Subtraction"
echo "3.Multiplication"
echo "4.Division"
echo "Enter your choice"
read ch
case $ch in
    1)sum=`expr $n1 + $n2`
     echo "Sum ="$sum;;
        2)sum=`expr $n1 - $n2`
     echo "Sub = "$sum;;
    3)sum=`expr $n1 \* $n2`
     echo "Mul = "$sum;;
    4)sum=`expr $n1 / $n2`
     echo "Div = "$sum;;
    *)echo "Invalid choice";;
esac
echo "Do u want to continue ?"
read i
if [ $i != "y" ]
then
    exit
fi
done    










OUTPUT
***********
[04mca58@LINTEL 04mca58]$ sh calculator.sh
Enter any no.
121
 Enter one no.
 21
 Enter second no.
 58
 1.Addition
 2.Subtraction
 3.Multiplication
 4.Division
 Enter your choice
 1
 Sum =79
 Do u want to continue ?
 y
 1.Addition
 2.Subtraction
 3.Multiplication
 4.Division
 Enter your choice
 2
 Sub = -37
 Do u want to continue ?
 y
 1.Addition
 2.Subtraction
 3.Multiplication
 4.Division
 Enter your choice
 3
 Mul = 1218
 Do u want to continue ?
 y
 1.Addition
 2.Subtraction
 3.Multiplication
 4.Division
 Enter your choice
 4
 Div = 0
 Do u want to continue ?
 n
  
Share: 


Didn't find what you were looking for? Find more on Shell Script to make a menu driven calculator using case Or get search suggestion and latest updates.

Samuel Evans
Samuel Evans author of Shell Script to make a menu driven calculator using case is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!