I have to do this little work in PHP structured below, but I have a problem there in the interest rate formula, I did not understand how to apply it, I did like this:
/* Calcula os Juros
------------------------------------------------------------- */
function juros($dados){
$r = (($dados['preco'] * (1 + $dados['txjuros']) ^ $dados['parcelas'] ) * $dados['txjuros']) / ((1 + $dados['txjuros']) ^ $dados['parcelas'] - 1);
return $r;
}
The correct formula is in the image below:
Secondattempt:
Imadeanalgorithmwithadifferentformula,butthentheinterestwasfixed,regardlessofthenumberofparcels.
Thevalueofinterestshouldrisebyasmuchasapercentageofthevalueofeachparcel.
IfIput4installmentsisthesameamountofinterestthatifIput10installments,thenitiswrongso,shouldsetxinterestrateforfirstinstallmentandvalueyinterestforsecondinstallment.
Someonecanhelpmebyanalyzingmycode,theerrorshouldbeinthelogicofapplyingtheformulagrantedbytheteacher.
PHPcode:
link