《quantitative finance with cpp》阅读笔记4---一个用cpp计算银行存款利息的例子
作者:yunjinqi 类别:
日期:2023-11-24 09:59:21
阅读:518 次 消耗积分: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;
}