Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- option=x
- #sudo apt-get install bc
- areaOfSquare ()
- {
- printf "Please enter the length of a side of the square:\n"
- read side
- area=$((side**2))
- printf "The area of the square is: $area\n"
- }
- areaOfRectangle ()
- {
- printf "Please enter the length of the rectangle:\n"
- read length
- printf "Please enter the width of the rectangle:\n"
- read width
- area=$(($length * $width))
- printf "The area of the rectangle is: $area\n"
- }
- areaOfCircle ()
- {
- printf "Please enter the radius of the circle:\n"
- read radius
- area=$( echo "scale=6; $radius * $radius * 3.14159" | bc )
- printf "The area of the circle is: $area\n"
- }
- areaOfCylinder ()
- {
- printf "Please enter the radius of the top of the cylinder:\n"
- read radius
- printf "Please enter the height of the cylinder:\n"
- read height
- areaCircle=$( echo "scale=6; $radius * $radius * 3.14159" | bc )
- areaCylinder=$(echo "scale=6; $areaCircle * $height" | bc)
- printf "The area of the cylinder is: $areaCylinder\n"
- }
- printf "Use one of the following options:\n"
- printf "s: to calculate the area of a square\n"
- printf "r: to calculate the area of a rectangle\n"
- printf "c: to calculate the area of a circle\n"
- printf "cy: to calculate the area of a cylinder\n"
- until [ "$option" = "s" -o "$option" = "r" -o "$option" = "c" -o "$option" = "cy" ]
- do
- printf "Please enter your option:\n"
- read option
- # if [ "$option" != "s" -o "$option" != "r" -o "$option" != "c" -o "$option" != "cy" ]
- # then
- # printf "You have entered an incorrect option.\n"
- # fi
- done
- case "$option" in
- s) areaOfSquare
- ;;
- r) areaOfRectangle
- ;;
- c) areaOfCircle
- ;;
- cy) areaOfCylinder
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement