复利公式

Compound interest rate formula

本文关键字:      更新时间:2023-10-16

这太令人沮丧了。我在任何地方都找不到这个答案,我自己也想不通。这是针对大学课堂上的作业。我们应该得到以下结果:

在10

年内,每月存入100美元将增长到17793.03美元

如何使用 c++ 计算?

定期存款公式可以应用

M = R * ( (1+r/p)^n-1 )/( (1+r/p) -1) = R * p/r * ( (1+r/p)^n-1 )
M is Maturity value
R is deposit amount
r is rate of interest
p is the number of parts of the year that is used, i.e., p=4 for quarterly and p=12 for monthly, 
n is the number of payments, i.e., the payment schedule lasts n/p years, and then r is the nominal annual interest rate, used in r/p to give the interest rate over each part of the year

工作代码如下:

#include <iostream>
#include <cmath>
using namespace std;
int main() {
    double r = 7.5 / 100;
    int n = 120;
    int p = 12;
    int R = 100;
#if 0
    double result = 0;
    for( int i = 0 ; i < n ; ++i )
    {
        result *= ( 1 + r/p ) ;
        result += R;
    }
#else
    double result = R * (p/r )* ( pow( (1+r/p), n ) - 1 );
#endif
    std::cout<<result;
return 0;
}
#include <iomanip>
#include <iostream>
int main()
{
    auto balance = 0.0;
    for (auto i = 0; i < 120; ++i)
        balance = balance * (1 + 0.075/12) + 100;
    std::cout << std::setprecision(7) << balance << 'n';
}
A = P (1 + r/n) ^ nt

这是每年复利复利的公式。

A = the future value of the investment/loan, including interest
P --> Principal amount (The starting amount)
r --> rate (%)
n --> the number of times that interest is compounded per year
t --> t = the number of years the money is invested or borrowed for

使用上面的公式并替换值,让计算机完成其余的工作。我希望这对您有所帮助.我只是一个初学者。这就是我认为我会这样做的方式。

编辑

抱歉,我之前提到的公式对于这样的问题不正确。这是正确的公式:-

PMT * (((1 + r/n)^nt - 1) / (r/n))
PMT--> Principal amount deposited monthy (100 $)

其余值保持不变。试试这个并将值存储在双精度中。这应该有效。我在代码块中尝试过这个。小心值和括号。

希望这有帮助。

相关文章:
  • 没有找到相关文章