pow problem

Hello,
I'm really new to C++ and having difficulties with my mortgage problem,
With my code, I am getting these errors:
c:\users\yin\documents\visual studio 2010\projects\assign3\assign3\assign3.cpp(38): error C2668: 'pow' : ambiguous call to overloaded function
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(583): could be 'long double pow(long double,int)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(535): or 'float pow(float,int)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(497): or 'double pow(double,int)'
1> while trying to match the argument list '(int, int)'

I can't get the pow to work to solve for "Your monthly payment is" and I'm not sure what I am doing wrong for the last error?

Any help is greatly appreciated!

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
cout << "Welcome! You may request loan payment info for a maximum of 5 loans, up to $999,999, and can terminate by -1\n";
bool finished = false;

int j=1;
while( !finished && j<=5)
{
double answer;
cout << "What is the amount of purchase?" << endl;
cin >> answer;

int payment;
if (answer < 999999)
{
cout << "What is your down payment?" << endl;
cin >> payment;

int i;
if (payment < 999999)
{
cout << "Your interest rate is\n" << endl;
cin >> i;}

else if (payment > 999999)
{
cout << "Choose an amount < 999999" << endl;
}

int y= 30;
int t=y*12;
double mPayment;

mPayment = ((answer-payment)*i)/(1-pow(1+i,-t));
cout<< "Your Monthly Payment is: $\n" << mPayment;



{
if (payment <= 5000)
cout << "7.1%\n" << endl;
else if (payment > 5000 && payment <= 7500)
cout << "6.3%\n" << endl;
else if ((payment > 7500) && (payment <= 10000))
cout << "5.5%\n" << endl;
else if ((payment > 10000) && (payment <= 15000))
cout << "5%\n" << endl;
else if ((payment > 15000) && (payment <= 20000))
cout <<"4.5%\n" << endl;
else if (payment > 20000)
cout <<"4.25%\n" << endl;

switch (payment)
{
case 5000:
cout << "interest = 7.1" ;
break;
case 7500:
cout << "interest = 6.3" ;
break;
case 10000:
cout << "interest = 5.5" ;
break;
case 15000:
cout << "interest = 5" ;
break;
case 20000:
cout <<"4.5%\n" << endl;
break;

}
}
}
else if (answer > 999999)
{
cout << "Choose an amount <999999" << endl;
}


char tempChar;
cout << "Do you wish to loop through the code again? [Y/N]: ";
cin >> tempChar;

if( tempChar == 'N' || tempChar == 'n' )
finished = true; j++;

}

system ("pause");
return 0;
}
Notice what type of parameters you are passing to pow function:
 
pow(1+i,-t)

and what is it expect to be: http://www.cplusplus.com/reference/clibrary/cmath/pow/

you can try casting first param into double.
Last edited on
um. if you are really new to C++ try posting in the begginers section =P
and please put your code in tags so people can read it and help you..
like this:


(code)
code goes here..
(/code)

only instead of using parentheses, use brackets like this [code]

or just use the source code button to the right under format -->
Topic archived. No new replies allowed.