C 抵押付款计算器公式
C++ Mortgage payment calculator formula
我一直在为C 类的抵押计算器工作。但是,我被卡住了。
我从Nerdwallet中获得了以下公式,并尝试在我的程序中实现它:
m = p [i(1 i)^n]/[(1 i)^n - 1]
m =抵押付款
p = principal
i =兴趣
n =付款数
这是我当前正在使用的代码。
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(int argc, char** argv)
{
int years, homePrice, creditScore, totalPayments;
float rate, mortgageTotal, monthlyPayment;
cout << "What is the price of the home that you are looking to mortgage?n";
cin >> homePrice; //Assigns the variable homePrice to a value
cout << "What is your credit score?n";
cin >> creditScore; //Assigns the creditScore variable a value
cout << "Would you prefer a 15 year or 30 year mortgage? Please type 15 or 30.n";
cin >> years;
if ( years = 15 ) //If input is 15 year it will go down this logical path
{
if (creditScore >=760) //If their credit rating is equal to or more than 760, their rate will be .043 also nested if.
{
rate = .043;
cout << "Your interest rate is 4.3%n";
}
else if (creditScore >= 700) //If their credit rating is equal to or more than 700, their rate will be .0455
{
rate = .0455;
cout << "Your interest rate is 4.55%n";
}
else if (creditScore >= 660) //If their credit rating is equal to or more than 660, their rate will be .048
{
rate = .048;
cout << "Your interest rate is 4.8%n";
}
else if (creditScore >= 620) //If their credit rating is equal to or more than 620, their rate will be .058
{
rate = .058;
cout << "Your interest rate is 5.8%n";
}
else if (creditScore >= 580) //If their credit rating is equal to or more than 580, their rate will be .0655
{
rate = .0655;
cout << "Your interest rate is 6.55%n";
}
else if (creditScore >= 500) //If their credit rating is equal to or more than 500, their rate will be .083
{
rate = .083;
cout << "Your interest rate is 8.3%n";
}
}
else if ( years=30 )
{
if (creditScore >= 760)
{
rate=.043;
cout <<"Your interest rate is 4.3%n";
}
else if (creditScore >= 700)
{
rate=.0455;
cout << "Your interest rate is 4.55%n";
}
else if (creditScore >= 660)
{
rate=.048;
cout << "Your interest rate is 4.8%n";
}
else if (creditScore >= 620)
{
rate=.058;
cout << "Your interest rate is 5.8%n";
}
else if (creditScore >= 580)
{
rate=.0655;
cout << "Your interest rate is 6.55%n";
}
else if (creditScore >= 500)
{
rate=.083;
cout << "Your interest rate is 8.3%n";
}
}
totalPayments = years * 12;
monthlyPayment = homePrice * [[rate * (1 + rate)pow(totalPayments)] / [(1 + rate)pow(totalPayments) - 1]];
mortgageTotal = monthlyPayment * totalPayments;
cout << "Your mortgage will cost approximately " << mortgageTotal << " and your monthly payment will be " << monthlyPayment << endl;
return 0;
}
但是,当我去编译时,我会收到以下错误:
错误
我只是不明白错误以及为什么在那里。
如果有人可以帮助我,我会非常感谢。
谢谢。
当您的数学公式同时使用[]
s和 ()
s进行分组表达式时,只能以()
s的方式使用C 。
pow
是一个函数调用,而不是像您似乎正在使用的那样的现场运算符。它需要看起来像pow(1 + rate, totalPayments)
。
您的if
S也在进行分配(=
)而不是比较(==
)。实际上,您的代码仅遵循第一个if
,因为它将years
设置为15。
您的抵押公式似乎是错误的。尝试这个
monthlyPayment = homePrice * ((rate * pow(1 + rate, totalPayments)) /
(pow(1.00 + rate, totalPayments) - 1));
相关文章:
- 使用 BMI 计算器对C++中的数字进行四舍五入的问题
- 我在c ++矩阵计算器程序中找不到错误
- C++计算器,不能单独除以 0
- 如何正确解析子字符串,以便它们对我的新手计算器有效?
- Arduino 基础 2 计算器无法C++工作
- 需要有关我的平均计算器代码的建议
- C++ - 在我尝试制作一个简单的计算器时有一个"uninitialized local variable y used"警告
- 野牛/flex:计算器将双精度值解释为整数,所以我添加了 YYSTYPE 双精度 #define 但我有多个编译错误
- C++计算器运算符
- 比较付款数据
- 使用WIN32 API的击球平均计算器
- RPN计算器c++错误处理和多个运算符
- C++查找用于构建单行计算器
- 如何修复这个基本计算器
- 用于加法和减法的十六进制计算器
- 桌面计算器出现问题.C++程序设计语言
- 如何对堆栈中的所有项目求和?Postfix计算器
- RPN计算器使用头文件进行计算操作和堆栈;用于堆栈的矢量
- 如何在我的基本计算器中循环遍历数组
- C 抵押付款计算器公式