Reputation: 25
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char *argv[])
{
double amount, rate, time, interest, month;
interest = rate/(12.0*100);
month = (amount * rate)/1.0 -(1.0 + interest), pow(time*12);
cout << "What is the amount of the loan? $ ";
cin >> amount;
cout << "What is the annual percentage rate? ";
cin >> rate;
cout << "How many years will you take to pay back the loan? ";
cin >> time;
cout <<"\n-------------------------------------------------------\n";
cout << "Amount Annual % Interest Years Monthly Payment\n\n\n";
cout <<amount <<" " <<rate <<" " <<time << " " <<month;
cout <<"\n\n";
system("PAUSE");
return EXIT_SUCCESS;
}
I am getting an error here and am not sure exactly how to use the pow function properly. The formula according to the problem is:
Monthly payment = (loan amount)(monthly interest rate) / 1.0 - (1.0 + Monthly interest rate)^-(number of months)
Here is the line that I am having trouble with
month = (amount * rate)/1.0 -(1.0 + interest), pow(time*12);
Thanks for the help
Upvotes: 0
Views: 4634
Reputation: 9841
std::pow
accepts two arguments like so
pow (7.0,3)
So your code should be more like this
month = (amount * rate)/1.0 - std::pow( (1.0 + interest), 12);
Your code has other flaws as well, like you do calculation before you set the values.
Upvotes: 2