0
#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

任何帮助,将不胜感激。

4

1 回答 1

5

1.542 180大于 7,164,522,793,368,325,816,802,274,738,448,555。这是一个很大的数字,你确定它适合你的浮点类型吗?

根据您在下面的评论,您似乎想要使用 1.00542。您还有其他几个错误的信息副本 ( MONTHLY_RATE, FORMULA_RATE)。

于 2013-03-05T01:56:47.027 回答