【发布时间】:2017-10-12 05:26:12
【问题描述】:
#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));)。我不确定我的代码有什么问题。
【问题讨论】:
-
按揭公式是什么?
-
抵押贷款总成本为 365 美元
-
您输入的汇率是 4.5 还是 0.0045?
-
你认为你没有从你的函数返回的所有局部变量发生了什么?
-
@HariomSingh 使用的抵押贷款公式是monthlyPayment = 本金 * 利率 / ( 1.0 – pow(rate + 1, -term));
标签: c++