【发布时间】:2020-01-28 08:16:24
【问题描述】:
我应该使用月利率公式:https://imgur.com/a/rQ3tbTs,其中 rate 是我写为 interestRate 的月利率,N 是我写为 amountOfPayments 的付款次数,LoanAmt 是金额贷款。
当我尝试将其放入我的程序中计算利息时,我最终得到的每月付款远远超过应有的金额。我认为我放入公式的代码行格式不正确。这是我的代码:
monthlyPayment = interestRate * pow(1 + interestRate, amountOfPayments) / pow(1 + interestRate, amountOfPayments) * borrowAmount
【问题讨论】:
-
与其尝试在一行代码中完成所有事情,不如考虑将其分解为更多变量。
top和bottom可以先设置,然后它只是(top/bot)*borrowAmount括号是免费的...不要害怕使用太多 -
我刚开始使用 C++,并不太了解。我不知道 top 和 bot 是什么意思。如果您只使用一行代码,您将如何格式化括号?
-
您在源代码中遗漏了一组括号和一个术语。准确复制。
-
因为你没有在你的问题中输入任何类型,所以我只举一个整数的例子
int top = interestRate * pow(1 + interestRate, amountOfPayments)int bot = pow(1 + interestRate, amountOfPayments) -1 -
您必须适当地更改变量的类型...整数当然会截断您的值