《quantitative finance with cpp》阅读笔记4---一个用cpp计算银行存款利息的例子
作者:yunjinqi   类别:    日期:2023-11-24 09:59:21    阅读:163 次   消耗积分:0 分    
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
    // Interesting code starts
    int principal;
    double interestRate;
    int numberOfYears;
 
    cout << "How much are you investing?\n";
    cin >> principal;
    cout << "What's the annual interest rate (%)?\n";
    cin >> interestRate;
    cout << "How long for (years)?\n";
    cin >> numberOfYears;
 
    double finalBalance =
        pow(1.0 + interestRate * 0.01, numberOfYears)
        * principal;
    double interest = finalBalance - principal;
 
    cout << "You will earn ";
    cout << interest;
    cout << "\n";
    /* Interesting code ends */
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/369
上一篇:《quantitative finance with cpp》阅读笔记3-为投资组合定价过程中的10个难题
下一篇:《quantitative finance with cpp》阅读笔记5---cpp根据不同考试成绩输出不同字符