Two integers are set -100<=a,b<=100. Find their a + b, a - b, a * b, and a / b.
So I need to output four numbers (sum, difference, product, and quotient) separated by a space to Terminal. If I can't find the quotient, I need to print the symbol "#" instead of the quotient result. Everything is fine but when I input numbers that are not included in that interval, it doesn't output 'a or b out of range'. The first part is just not working...
#!/bin/bash
a=$1
b=$2
if [[ -100 -ge $a && $a -ge 100 ]] || [[ -100 -ge $b && $b -ge 100 ]]
then
echo 'a or b out of range'
elif [[ $((a % b)) = 0 ]]
then
echo $((a + b)) $((a - b)) $((a * b)) $((a / b))
else
echo $((a + b)) $((a - b)) $((a * b)) '#'
fi
Aucun commentaire:
Enregistrer un commentaire