Created
January 15, 2016 23:25
-
-
Save raku-cat/abad9c27fa64bbdd72ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Script to determine the type of triangle based on side lenghts" | |
read -p "Enter a side length: " L1 | |
read -p "Enter other side length: " L2 | |
read -p "Enter the hypotenuse: " H | |
L1=$(echo "$L1*$L1"|bc) | |
L2=$(echo "$L2*$L2"|bc) | |
H=$(echo "$H*$H"|bc) | |
L=$(echo "$L1+$L2"|bc) | |
if (( $(bc <<< "$H==$L") )); then | |
TRIANGLE="right"; | |
elif (( $(bc <<< "$H>$L") )); then | |
TRIANGLE="obtuse"; | |
elif (( $(bc <<< "$H<$L") )); then | |
TRIANGLE="acute"; | |
else echo "Unable to determine triangle type :C"; | |
fi; | |
if [ -n ${TRIANGLE+x} ]; then | |
echo "The triangle is $TRIANGLE"; | |
fi; | |
read -p "Test another triangle?[D:N] " REPLY | |
REPLY=${REPLY:=N} | |
case $REPLY in | |
"Y" | "y" ) | |
bash triangle.sh | |
;; | |
"N" | "n" ) | |
exit 0 | |
;; | |
esac | |
exit 0 | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment