2
#include <iostream>
#include <cmath>
using namespace std;
/* FINDS AND INITIALIZES TERM */
void findTerm(int t) {
int term = t * 12;
}
/* FINDS AND INITIALIZES RATE */
void findRate(double r) {
double rate = r/1200.0;
}
/* INITALIZES AMOUNT OF LOAN*/
void findAmount(int amount) {
int num1 = 0.0;
}
void findPayment(int amount, double rate, int term) {
int monthlyPayment = amount * rate/(1.0 -pow(rate + 1, -term));
cout<<"Your monthly payment is $"<<monthlyPayment<<". ";
}
这是主要功能。我在做什么这个抵押贷款公式错了?
int main() {
int t, a, payment;
double r;
cout<<"Enter the amount of your mortage loan: \n ";
cin>>a;
cout<<"Enter the interest rate: \n";
cin>>r;
cout<<"Enter the term of your loan: \n";
cin>>t;
findPayment(a, r, t); // calls findPayment to calculate monthly payment.
return 0;
}
我跑了一遍又一遍,但它仍然给我不正确的金额。 我的教授给我们,是这样的一个例子: 贷款= $ 200,000个
率= 4.5%
期限:30岁
而且findFormula()函数将会产生$ 1013.67按揭付款。我的教授也给了我们这个代码(monthlyPayment = amount * rate /(1.0 - pow(rate + 1,-term));)。我不确定我的代码有什么问题。
什么是使用的mortage公式? –
抵押贷款的总成本达到$ 365 –
您是否将费率输入为4.5或0.0045? –