按揭计算器公式不正确

时间:2017-01-26 23:46:10

标签: c++

我正在为我的班级制作抵押贷款计算器,该程序运行但答案不正确,我认为我有正确的公式,但也许我宣布我的变量是错误的。

这是我到目前为止所拥有的

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    //Variables
    double rate;
    rate = rate / 1200.0;

    double term;
    term = term * 12;

    double principal;

    double monthlyPayment;
    monthlyPayment = (principal * rate) / (1.0 - pow(rate + 1, -term));


    //Gathering Values
    cout << "Please enter your interest rate." << endl;
    cin >> rate;

    cout << "Please enter your term." << endl;
    cin >> term;

    cout << "please enter your principal" << endl;
    cin >> principal;

    //Formula
    monthlyPayment = principal * rate / (1.0 - pow(rate + 1, -term));

    //Result
    cout << "Your monthly payment is, " << monthlyPayment << endl;

    return 0;
}

1 个答案:

答案 0 :(得分:0)

您在cin语句之前所做的所有数学计算都没有考虑在内。此外,计算monthlyPayment的第二个公式在分子中缺少括号。