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

Can someone help me out with this? I am struggling with this a bit. This needs t

ID: 3575536 • Letter: C

Question

Can someone help me out with this? I am struggling with this a bit. This needs to be a shell script that can be used on Linux, ubuntu specifically.

You will write a script that when executed, it will prompt a user with a menu. It is up to you how you want the user to input which menu selection. For example if the user enters in the number 1, then it will perform addition, entering in the number 2 will perform subtraction, 3 will multiply numbers, and 4 will divide numbers. You do not have to use these formulas. You can Have the script perform different functions such as if entering in the number 1, it will perform the quadratic equation, entering in menu 2 can perform binary addition or subtraction. You can use formulas that performs calculations calculating the radius or circumference of a circle or some calculus or physics equation. Just make sure that they produce the correct answer. Also, make sure you compensate for if a user inputs a wrong input variable. For example if they input E instead of 3. Your script needs to print an appropriate message and exit or notify the user and allows them to correct the input. Below is an example output:

Please select from the menu below, which mathematical equation you want to perform:

Enter 1 to add two numbers

Enter 2 to subtract two numbers

Enter 3 to multiply two numbers

Enter 4 to divide two numbers

Enter 5 to calculate the circumference of a circle

Enter 0 to exit the program

You entered 2. Now enter in the first number:

Now enter in the second number to subtract from the first number:

Your result is: Your answer here

Do you want to perform another calculation or exit the program.

Explanation / Answer

i="y";
while [ $i == "y" ]
do
   echo "1.Addition"
   echo "2.Subtraction"
   echo "3.Multiplication"
   echo "4.Division"
   echo "5.Calculate the circumference of a circle"
   echo "0.Exit"
   echo "Enter your Choice:"
   read -r choice
  
   if [ "$choice" -gt 0 ] && [ "$choice" -lt 5 ]
   then
       echo "Enter first value:"
       read -r a
       echo "Enter second value:"
       read -r b
   fi
  
   if [ "$choice" == 5 ]
   then
       echo "Enter radius of the circle:"
       read -r a
   fi

   case $choice in

   0)
       exit0;;

   1)
       sum=$(echo "$a + $b" | bc)
   echo "Sum of the given two numbers is: $sum" ;;

   2)
   sub=$(echo "$a - $b" | bc)
   echo "Substraction of the given two numbers is: $sub" ;;

   3)
   mul=$(echo "$a * $b" | bc)
   echo "Multiplication of the given two numbers is: $mul" ;;

   4)
   div=$(echo "$a / $b" | bc -l)
   echo "Division of the given two numbers is: $div" ;;
   5)
       circumference=$(echo "2* 3.14 * $a"| bc)
       echo "Circumference of the circle is: $circumference" ;;

*)
       echo "Invalid Choice"

   esac

echo "Do You Want To Continue? y/n"

read -r i

if [[ $i != "y" ]] ; then
echo "Thank You! Exit from the program"
exit0

fi

done

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