Question
Please help with code not getting proper numbers. Monthly payment is good. interest on chart/layout is way off. principle on chart is way off. total
Please help with code not getting proper numbers. Monthly payment is good. interest on chart/layout is way off. principle on chart is way off. total payments is o.k.. total interest is way off on chart.
#include
using namespace std;
void Getinput(double& P, double& r, int& n);
double MPay_formula (double P, double r, int n); //function that will compute M=P((r*(1+r)^n)/(((1+r)^n)-1)
void intPrinciple(double M, double P, double r, int n, double &interest, double &principal, double &balance); // calculates interest and balance for every month.
void totPaymentInterest(double M, double& totpayment, double& totinterest, double& interest); // keeps track of total payment and total interest accumulated.
void printresults(double m, double P, double r, int n, double interest, double principal, double balance, double totpayment, double totinterest);
int main() {
double P = 0, r = 0, interest, principal, balance, totpayment = 0, totinterest = 0; int n; cout
double M = MPay_formula (P, r / 12, n); cout
intPrinciple( M, P, r / 12, n, interest, principal, balance); totPaymentInterest(M, totpayment, totinterest, interest); printresults(M, P, r, n, interest, principal, balance, totpayment, totinterest); return 0; }
void intPrinciple(double M, double P, double r, int n, double &interest, double &principal, double & balance) { interest = P * r; principal = M - interest; balance = P - principal;
}
double MPay_formula(double P, double r, int n) { return ( P * (r*pow(1+r, n)) / (pow(1+r,n) - 1)) ; }
void totPaymentInterest(double M, double& totpayment, double& totinterest, double& interest) { totpayment += M; totinterest += M - (M - interest); }
void printresults(double M, double P, double r, int n, double interest, double principal, double balance, double totpayment, double totinterest) { ofstream outputFile("assignment_2output.txt"); cout
void Getinput(double& P, double& r, int& n) { cout > P;
cout > r; cout > n; cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started