Code In Tech - The Ultimate World of Computer Technology

Monday, 4 June 2012

Shell script to Create a calculator by case system

SOURCE CODE:

echo “Enter the values :”

echo “x:”
read x
echo “y:”
read y

echo “1: Addition”
echo “2: Subtraction”
echo “3: multiplication.”
echo “4: Division.”

echo “Enter the choice:”
read c

case “$c” in

ans =`expr $x + $y`;;

2)   ans =`expr $x - $y`;;

ans =`expr $x \ *y`;;

if [ $y != 0]
then
           ans =`expr $x / $y`;;
else
     echo “Invalid operation”
fi;;
esac

echo “Ans:“ $ans

OUTPUT

Enter the values :
X:
1
Y:
3
1: Addition
2: Subtraction
3: multiplication
4: Division

Enter the choice:
3
Ans:3 

No comments :

Post a Comment