This is a UNIX script Using the c shell /bin/csh write the utility called myCalc
ID: 3682127 • Letter: T
Question
This is a UNIX script Using the c shell /bin/csh write the utility called myCalc that satisfies the following specifications:
Usage: myCalc operand1 operator operand2
myCalc is a very simple calculator. operand1 and operand2 are integers. operator is the words plus, minus, div, and times. The operands and operators will be passed on the command line. Generate error messages if the operands are not valid or the operator is not valid. If no arguments are passed show the usage statement. Example of what the command line will look like:
>myCalc 2 plus 3
>The answer is 5
Explanation / Answer
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
plus)sum=`expr $n1 + $n2`
echo "Sum ="$sum;;
minus)sum=`expr $n1 - $n2`
echo "Sub = "$sum;;
mul)sum=`expr $n1 * $n2`
echo "Mul = "$sum;;
div)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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.