Skip to content

Instantly share code, notes, and snippets.

@raku-cat raku-cat/triangle.sh
Created Jan 15, 2016

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.