Logo 
Search:

Unix / Linux / Ubuntu Articles

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

Prepare a menu driven calculator

Posted By: Raoul Fischer     Category: Unix / Linux / Ubuntu     Views: 5294

Prepare a menu driven calculator

Code for Prepare a menu driven calculator in Unix / Linux / Ubuntu

count=0
while [ $count -eq 0 ]
do
tput clear

echo "1. Addition"
echo "2. Subtracation"
echo "3. Multiplication"
echo "4. Division"
echo "5. Exit"
echo "Enter your choice"
read choice

if [ $choice -eq 1 ]
then
        echo "Enter first no "
        read first
        echo "Enter second no "
        read second
        echo `echo $first + $second | bc`
elif [ $choice -eq 2 ]
then
        echo "Enter first no "
        read first
        echo "Enter second no "
        read second
        echo `echo $first - $second | bc`
elif [ $choice -eq 3 ]
then
        echo "Enter first no "
        read first
        echo "Enter second no "
        read second
        echo `echo $first \* $second | bc`
elif [ $choice -eq 4 ]
then
        echo "Enter first no "
        read first
        echo "Enter second no "
        read second
        echo `echo $first / $second | bc`
else
        count=1
        exit
fi
echo "Do you continue (1 for y/ 0 for n) "
read ch
if [ $ch -eq 1 ]
then
        count=0
else
        exit
fi
done
  
Share: 


Didn't find what you were looking for? Find more on Prepare a menu driven calculator Or get search suggestion and latest updates.

Raoul Fischer
Raoul Fischer author of Prepare a menu driven calculator is from Frankfurt, Germany.
 
View All Articles

 
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!