?? mog.cc
字號:
// This program computes monthly payment of a fixed
// rate mortgage. It computes correctly in the sense that
// it produced exactly the same result as my mortgage.
#include <iostream>
double mnpay(double tsum, double mrate, int tmonths) {
// it returns the monthly payment of a fixed rate
// mortgage of amount "tsum" with
// rate "mrate" and total months "tmonths" of length
std::cout << "mortgage rate = " << mrate << " percent\n";
std::cout << "mortgage amount = " << tsum << '\n';
std::cout << "length of mortgage in months = " << tmonths << '\n';
std::cout << "length of mortgage in years = " << tmonths/12.0 << '\n';
long double tmp = 1.0/(1.0 + 0.01*mrate/12.0);
long double u = 1;
for (int i = 1; i < tmonths; i++) u = 1 + tmp*u;
u = tmp*u;
return tsum/u;
}
int main () {
// for a 15 year mortgage of $200000 with rate 6.25%.
double mp= mnpay(200000, 6.25, 15*12);
std::cout << "monthly payment = " << mp << '\n';
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -