tkcartoonist
Tunes and Toons
So I'm working on a project that involves writing a PowerShell script for some kind of useful, everyday function. I remembered a bash script I typed up a while back that helps calculate interest to be paid back on a loan, and I wanted to convert it into a PowerShell-usable script. However, I'm having a bit of a go when it comes to reworking function and variable syntax to make the PowerShell program 1-to-1 with the original bash version. I was wondering if anyone could help me out here. I'll post the original bash code below to review.
Bash:
#!/bin/bash
# loan-calc: script to calculate monthly loan payments
PROGNAME="${0##*/}" # Use parameter expansion to get basename
usage () {
cat <<- EOF
Usage: $PROGNAME PRINCIPAL INTEREST MONTHS
Where:
PRINCIPAL is the amount of the loan.
INTEREST is the APR as a number (7% = 0.07).
MONTHS is the length of the loan's term.
EOF
}
if (($# != 3)); then
usage
exit 1
fi
principal=$1
interest=$2
months=$3
bc <<- EOF
scale = 10
i = $interest / 12
p = $principal
n = $months
a = p * ((i * ((1 + i) ^ n)) / (((1 + i) ^ n) - 1))
print a, "\n"
EOF