在表达式中使用pow函数
using pow function in an expression
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
// Defining Variable
using namespace std;
const int MONTHS_IN_YEAR = 12;
const int PURCHASE_PRICE= 123500;
const int AMOUNT_MORG= 111150;
const int DOWN_PAYMENT = 12350;
const float MONTHLY_RATE= 0.542f;
const float FORMULA_RATE=1.542f;
float PAYMENT;
int main()
{
PAYMENT= (float)(MONTHLY_RATE*AMOUNT_MORG)*(pow(1.542,180));
cout << PAYMENT;
cout << fixed << showpoint << setprecision(2);
system ("cls");
cout <<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$";
cout <<'$';
cout << setw(79)<<'$';
cout<<'$';
cout << setw(79)<<'$';
cout << '$';
cout << setw(79)<<'$';
cout << '$'<<" " <<"Welcome to the mortgage information calculator 2013"
<<" " << '$';
cout <<'$';
cout << setw(79)<<'$';
cout<<'$';
cout << setw(79)<<'$';
cout <<'$'<< " "<< " Made exclusively for Dewey,Cheatum and Howe bankers"
<<" "<<'$';
cout <<'$';
cout << setw(79)<<'$';
cout<<'$'<<" "<< "by: Steven Fisher"
<<" "<<'$';
cout <<'$';
cout << setw(79)<<'$';
cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
system ("pause");
return 0;
}
这是我的代码。我是c++语言的新手,我在课堂上被分配了一个项目,我必须计算房屋抵押贷款的月供。
我需要使用pow
函数并将幂乘以一个表达式。下面是我的尝试:
(float)(MONTHLY_RATE*AMOUNT_MORG)*(pow(1.542,180))
,当我运行程序时,我得到的答案是1.#inf
。
1.542180大于7,164,522,793,368,325,816,802,274,738,448,555。这是一个相当大的数字,你确定它适合你的浮点类型吗?
根据您下面的评论,看起来您想使用1.00542。
MONTHLY_RATE
, FORMULA_RATE
)。
相关文章:
- 在 while 循环中使用 pow() 函数 C++
- C++ 中 pow() 函数的输出没有给出准确的答案
- 无法在 for 循环中的 pow 函数上输出答案
- 如何在while内部执行pow函数?C++
- POW函数为什么返回意外值
- 如何将POW函数矢量化(具有负碱基)
- 为什么math.h的pow函数返回无穷大的值
- C++将pow函数的双结果强制转换为整数
- 仅使用加法的pow函数
- Pow 函数 C++ 错误
- 提升 使用带有cpp_dec_float的 pow 函数
- 为什么pow函数给我nan作为答案
- constexpr与模板、pow函数的对比
- 如何避免pow函数用数字除法时出现整数溢出
- 使用sqrt()和pow()函数会产生不同的结果
- 指定 cmat 的 pow 函数,而不是本地声明的函数
- Math.h pow()函数不能正常工作
- 在表达式中使用pow函数
- C++pow函数得到了一个奇怪的结果
- 对如何使用pow()函数来负功率的东西感到困惑