C++ help
#include <iostream>; #include <iomanip>; #include <string> using namespace std; int main() { int yearRate, payments; double loan, monthPay, paidBack, interest, rate; cout << setprecision(2) << fixed; //gets loan amount, cout << "Enter the loan amount => "; cin >> loan; //gets yearly interest rate cout <<"Enter the yearly interest rate as a percentage => "; cin >> yearRate; //gets number of payments cout << "Enter the number of payments "; cin >> payments; //This is where the formula goes //outputs the loan, yearRate, payments, monthPay, paidBack, and interest variables cout << "Loan Amount: $ " << loan; cout << "Yearly Interest Rate: $ " << yearRate; cout << "Number of Payments: $ " << payments; cout << "Monthly Payment: $ " << monthPay; cout << "Amount Paid Back: $ " << paidBack; cout << "Interest Rate: $ " << interest; //option to end program cin.ignore(); cout << "Press enter to end"; cin.get(); return 0; }
Payment = (Rate * (1 + Rate)^N)/(((Rate + 1)^N) - 1)
Payment is the monthPay variable. Rate is the rate variable. N is the payment variable. L is the loan variable.
I need to turn the "//This is where the formula goes" section into a c++ formula that is the same as the formula i listed
ther is no ^ operator. There is a pow function in cmath
i know, the formula i listed is not cmath, i need to convert it
the only way that i can incorporate the exponents is by making another variable
from what i can tell
what's wrong with rate * pow((1+rate),n) etc.
\[Payment = \frac{Rate * (1 + Rate)^{N} }{ ((1 + Rate)^{N} - 1} * L\] this is how the original formula looks
umm i don't know, does that work?
btw there is a ) after the -1 i forgot to add
thx for ur help, that does seem to work
\[Payment = \frac{Rate * pow((1 + Rate),N) }{ pow((1 + Rate),N) - 1} * L\] yep. no problem
Join our real-time social learning platform and learn together with your friends!