## 7 Replies - 4039 Views - Last Post: 17 September 2010 - 02:37 PM

### #1 PsychoCoder Reputation: 1659
• Posts: 19,853
• Joined: 26-July 07

# Compound Interest Calculator

Posted 01 February 2008 - 09:57 PM

Description: Provide a loan amount, interest rate and length of loan and the snippet will calculate the compound interestThis is a snippet that can be used to calculate compound interest.

Is This A Good Question/Topic? 0

## Replies To: Compound Interest Calculator

### #2 novincetr Reputation: 0
• Posts: 0
• Joined: 17-July 08

## Re: Compound Interest Calculator

Posted 16 July 2008 - 10:39 PM

Firstly, it does not work. And when you get it work by removing some quotes, you double your money just within 2 years. When you delete the entire "if..else" stuff, the code calculates compound interest! Secondly, compound interest is a power function: \$totalAtTheEndOfPeriod = \$InitialCapital * pow(1+\$InterestRate, \$loanLength); Simply as that

### #3 Noßalgììa Reputation: 0
• Posts: 0
• Joined: 17-September 10

## Re: Compound Interest Calculator

Posted 17 September 2010 - 02:19 PM

or, try this:

"<html>
<body bgcolor="black">

<font color="darkred">

<form action="total.php" method="post"><br/>
Principal: \$<input type="text" name="principal" />

Interest Rate: <input type="text" name="inrate" />%

Time(In Years[i.e. 6 monthes = .5 years]) <input type="text" name="time" />

<input type="submit" name="Calculate" value="Calculate"
</font>
</body>
</html>"

"<html>
<body bgcolor="black">

<font color="darkred">
<center>Your Principal is \$<?php echo \$_POST["principal"]; ?>.

Your Interest Rate is <?php echo \$_POST["inrate"]; ?>%.

Your Loan is for
<?php
if (\$_POST["time"]==1)
echo \$_POST["time"] . " year.";
else
echo \$_POST["time"] . " years.";
?>

<?php
\$p=\$_POST["principal"];
\$i=(\$_POST["inrate"]/100);
\$t=\$_POST["time"];
\$n=365;
\$a=(1 + (\$i/365));
\$b=(\$n*\$t);
\$total=\$p*(pow(\$a, \$b));
if
(
\$p=\$_POST["principal"] &&
\$i=(\$_POST["inrate"]/100) &&
\$t=\$_POST["time"] &&
\$n=365 &&
\$a=(1 + (\$i/365)) &&
\$b=(\$n*\$t) &&
\$total=\$p*(pow(\$a, \$b))
)
echo \$total
?>
</center>

</font>
</body>
</html>"

I know some of that seems redundant, but i kept getting an unexpected T_ECHO error without the if statement. It works, and it works well, and isn't that what we're all shooting for???

### #4 Noßalgììa Reputation: 0
• Posts: 0
• Joined: 17-September 10

## Re: Compound Interest Calculator

Posted 17 September 2010 - 02:19 PM

wow, thats dumb, here let me try that again lol

### #5 Noßalgììa Reputation: 0
• Posts: 0
• Joined: 17-September 10

## Re: Compound Interest Calculator

Posted 17 September 2010 - 02:25 PM

well w/e, fail i guess... I'll post my compound interest formula later

### #6 Noßalgììa Reputation: 0
• Posts: 0
• Joined: 17-September 10

## Re: Compound Interest Calculator

Posted 17 September 2010 - 02:33 PM

first site-

```<html>
<body bgcolor="black">

<font color="darkred">

<form action="total.php" method="post"><br/>
Principal: \$<input type="text" name="principal" />

Interest Rate: <input type="text" name="inrate" />%

Time(In Years[i.e. 6 monthes = .5 years]) <input type="text" name="time" />

<input type="submit" name="Calculate" value="Calculate"
</font>
</body>
</html>

```

links to this site:
```<html>
<body bgcolor="black">

<font color="darkred">
<center>Your Principal is \$<?php echo \$_POST["principal"]; ?>.

Your Interest Rate is <?php echo \$_POST["inrate"]; ?>%.

Your Loan is for
<?php
if (\$_POST["time"]==1)
echo \$_POST["time"] . " year.";
else
echo \$_POST["time"] . " years.";
?>

<?php
\$p=\$_POST["principal"];
\$i=(\$_POST["inrate"]/100);
\$t=\$_POST["time"];
\$n=365;
\$a=(1 + (\$i/365));
\$b=(\$n*\$t);
\$total=\$p*(pow(\$a, \$b));
if
(
\$p=\$_POST["principal"] &&
\$i=(\$_POST["inrate"]/100) &&
\$t=\$_POST["time"] &&
\$n=365 &&
\$a=(1 + (\$i/365)) &&
\$b=(\$n*\$t) &&
\$total=\$p*(pow(\$a, \$b))
)
echo \$total
?>
</center>

</font>
</body>
</html>

```

### #7 Noßalgììa Reputation: 0
• Posts: 0
• Joined: 17-September 10

## Re: Compound Interest Calculator

Posted 17 September 2010 - 02:36 PM

there we go, the bg color and font color are just things i like. i hate white pages with black letters if there's nothing else on the page to make it interesting. also note: only the second file has to be saved as php, the first file is just an html. hope that helps everyone out a little.

### #8 Noßalgììa Reputation: 0
• Posts: 0
• Joined: 17-September 10

## Re: Compound Interest Calculator

Posted 17 September 2010 - 02:37 PM

I know some of that seems redundant, but i kept getting an unexpected T_ECHO error without the if statement. It works, and it works well, and isn't that what we're all shooting for???

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }