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

#1 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • 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  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#3 Noalga  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 17-September 10

Re: Compound Interest Calculator

Posted 17 September 2010 - 02:19 PM

or, try this:

i have this page-

"<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>"

Linking to this page-

"<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.";
?>

Your total is:
<?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???
Was This Post Helpful? 0
  • +
  • -

#4 Noalga  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#5 Noalga  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#6 Noalga  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.";
?>

Your total is:
<?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>


Was This Post Helpful? 0
  • +
  • -

#7 Noalga  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#8 Noalga  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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???
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1