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

}

So here is my code. I'm new to the C++ language and I was assigned a project in class and I have to calculate the monthly payment for a house mortgage.

I need to use the pow function and multiply the power by an expression. Here's what I tried:

(float)(MONTHLY_RATE*AMOUNT_MORG)*(pow(1.542,180))

and when I run the program I get an answer of 1.#inf.

Any help would be appreciated.

有帮助吗?

解决方案

1.542180 is more than 7,164,522,793,368,325,816,802,274,738,448,555. That's a pretty big number, are you sure it fits in your floating point type?

Based on your comments below, it looks like you want to be using 1.00542. You have several other copies of that information that are wrong too (MONTHLY_RATE, FORMULA_RATE).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top