Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is in UNIX You are to write a shell program (script) to do the following. D

ID: 3826493 • Letter: T

Question

This is in UNIX

You are to write a shell program (script) to do the following. Display following menu: 1 - add two numbers 2 - subtract two numbers You are to write a shell program (script) to do the following. Display following menu: 1 - add two numbers 2 - subtract two numbers 3 - multiply two numbers 4 - divide two numbers Enter your choice: Enter your two numbers: The answer is: READ the users choice of operations, then read the two numbers the user enters. Based upon the users choice, and using the test operator, calculate the users answer. Keep in mind such things as invalid input, illegal math operations, friendly user interaction, etc. Note this will require week 10 class info. 3 - multiply two numbers 4 - divide two numbers Enter your choice: Enter your two numbers: The answer is: READ the users choice of operations, then read the two numbers the user enters. Based upon the users choice, and using the test operator, calculate the users answer. Keep in mind such things as invalid input, illegal math operations, friendly user interaction, etc. Note this will require week 10 class info.

Explanation / Answer

echo "Display following menu"
echo "1- add two numbers"
echo "2- subtract two numbers"
echo "3- multiply two numbers"
echo "4- divide two numbers"

echo -n "Enter your choice (1-4) : "
read choice
echo -n "Enter your two number : "
read n1
read n2


if [ $choice -eq 1 ]
then
answer="The answer is = $(( $n1 + $n2 ))"

elif [ $choice -eq 2 ]
then
answer="The answer is = $(( $n1 - $n2 ))"
elif [ $choice -eq 3 ]

then
answer="The answer is = $(( $n1 * $n2 ))"
elif [ $choice -eq 4 ]
then
   if[ $n2 -eq 0]
   then
   answer= "Can't divide"
   else
    answer="The answer is = $(( $n1 / $n2 ))"
else
echo "Sorry please select number between 1-4 only"
exit 1
fi
echo $answer

here is the shell programming code

in this i have taken 2 variables as n1 and n2, for these we are calculating the all 4 operations as addition, subtraction, multiplication and division for the user which enters the value between 1-4.

according to which the answer will be calculated and given as answer.

for division i am checking if the second number n2, if its equals to 0 then its giving the answer as cant divide else calculating the division of 2 numbers n1 and n2.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote