Could someone provide me the prompts for Linux to complete the following task? T
ID: 3919635 • Letter: C
Question
Could someone provide me the prompts for Linux to complete the following task?
Thank you!
Part IScript should contain the following tasks:
Script file name: math.sh
Clear the screen.
Enter appropriate comments or descriptions
Ask the user to input a value for each arithmetic calculations; for example, 1 for addition and 2 for subtraction, so on.
Use a case statement condition and the user input, complete arithmetic operations.
Print the result on the screen.
Part II Test your program.
Give proper execute permission to run the script
Explanation / Answer
CODE :-
$clear
res=0
i="y"
# Take user Input
echo " Enter Two numbers:"
read a
read b
while [ $i="y" ]
do
# Calculator operations
echo "1.Addition"
echo "2.Subtraction"
echo "3.Multiplication"
echo "4.Division"
echo "Enter your choice"
read ch
# Switch Case to perform
# calulator operations
case $ch in
1)res=`expr $a + $b`
echo "Sum ="$res;;
2)res=`expr $a - $b`
echo "Sub = "$res;;
3)res=`expr $a * $b`
echo "Mul = "$res;;
4)res=`expr $a / $b`
echo "Div = "$res;;
*)echo "Please enter valid choice";;
esac
echo "Do you 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.