6. write a menu driven program to calculate i) simple interest ii) compound interest (interest.sh)
while [ 1 ]
do
echo "menu"
echo "1. simple interest"
echo "2. compound interest"
echo "3. exit"
echo "enter the choice"
read choice
case $choice in
1) echo "enter the value of p,t and r"
read p
read t
read r
si=`echo "scale=2;( $p * $t * $r ) / 100" | bc`
echo "simple interest = $si" ;;
2) echo "enter the value of p, t, r and n"
read p
read t
read r
read n
power=`expr $n \* $t`
echo $power
ci=`echo "scale=2; ( $p * ( 1 + $r / $n ) ) ^ $power" | bc`
echo "compound interest = $ci" ;;
3) exit;;
*) echo "invalid choice";;
esac
done
do
echo "menu"
echo "1. simple interest"
echo "2. compound interest"
echo "3. exit"
echo "enter the choice"
read choice
case $choice in
1) echo "enter the value of p,t and r"
read p
read t
read r
si=`echo "scale=2;( $p * $t * $r ) / 100" | bc`
echo "simple interest = $si" ;;
2) echo "enter the value of p, t, r and n"
read p
read t
read r
read n
power=`expr $n \* $t`
echo $power
ci=`echo "scale=2; ( $p * ( 1 + $r / $n ) ) ^ $power" | bc`
echo "compound interest = $ci" ;;
3) exit;;
*) echo "invalid choice";;
esac
done
Leave a Comment