C++计算未来利率程序

来源:互联网 发布:宁弈对知微的爱 编辑:程序博客网 时间:2024/04/29 01:27

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
double futureInvestmentValue(
 double investmentAmount, double monthlyInterestRate, int years)
{
 double accumulatedValue;  
    accumulatedValue=
  investmentAmount* pow(1+monthlyInterestRate,years*12);
      cout<<left<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<years<<left<<setw(10)<<accumulatedValue<<'\n';

   return 0;
}

int main()
{
 cout<<"投资额: 1000"<<'\n'<<"年利率:9%"<<endl;
 cout<<left<<setw(5)<<"年"<<setw(10)<<"未来价值"<<endl;
 for(int years=1;years<=30;years++)
 {
  futureInvestmentValue(1000,0.09/12,years);
  
 }
 return 0;
}