【发布时间】: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++