【问题标题】:c++ mortgage calculator - term does not evaluate to a function taking 1 argumentsc++ 抵押计算器 - 术语不计算为带 1 个参数的函数
【发布时间】:2021-05-08 06:34:49
【问题描述】:

我需要编写一个程序来计算每月的抵押贷款还款额。我得到的公式是

P = L[(r/12)(1+r/12)n]/[(1+r/12)n -1]

在哪里
P = 每月付款
L = 贷款金额
r = 利率
n = 贷款期限的月数。

在第 37 行

p = l * (r / 12)(1 + (r / pow(12, n))) / (1 + r / pow(12, n)) - 1;

我不断收到一条错误消息:

Expression preceding parentheses of apparent call must have (pointer-to-function type)  
Term does not evaluate to a function taking 1 arguments

我该如何解决这个问题?

这是我的全部代码:

#include <iostream>
#include <cmath>

using namespace std;


int main() {


    double p = 0, l = 0, d = 0, c = 0, r = 0;
    int n = 0;

    cout << "Welcome to the Mortgage Payment Calculator \n";

    cout << "Please enter the information \n";
    cout << "Cost of home: \n";
    cin >> c;
    cout << "Loan amount: \n";
    cin >> l;
    cout << "Interest rate: \n";
    cin >> r;
    cout << "Number of months on loan: \n";
    cin >> n;
    cout << "Downpayment: \n";
    cin >> d;


    cout << "Cost of home : " << c;
    cout << "Down Payment : " << d;
    cout << "Loan: " << c - d;
    cout << "Interest rate: " << r;
    cout << "Number of months for life of loan: " << n;
    cout << endl;

    //formula

    p = l * (r / 12)(1 + (r / pow(12, n))) / (1 + r / pow(12, n)) - 1;

    cout << "You owe the mortgage company: " << l - d;
    cout << "your monthly payment is: " << p << endl;



    return 0;
}

【问题讨论】:

    标签: c++


    【解决方案1】:

    这个词在这里:

    (r / 12)(1 + (r / pow(12, n)))
    

    这里没有像数学那样隐含的乘法。你需要指定乘法*

    (r / 12) * (1 + (r / pow(12, n)))
            ^^^
    

    【讨论】:

    • 我不知道我是怎么错过的,谢谢。
    • 这很容易做到,尤其是当错误消息(虽然对于编译器完全正确)不是立即清晰时。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2020-07-21
    • 1970-01-01
    • 2020-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多