#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函數
我需要使用pow
函數並將乘方乘以表達式。下面是我的嘗試:
(float)(MONTHLY_RATE*AMOUNT_MORG)*(pow(1.542,180))
,當我運行該程序,我得到的1.#inf
答案。
任何幫助,將不勝感激。
你的號碼非常大。如果你使用'double'而不是'float',你仍然可以在這個特殊情況下計算它(我試過)。但很明顯,數字和公式有什麼問題,或者你如何使用它們。不是真正的C++問題。 – jogojapan 2013-03-05 01:59:57