Я борюсь с этой программой на C ++, чтобы получить правильную сумму для ежемесячного платежа. Есть кое-что, что я делаю неправильно с формулой, которую я считаю, что я не могу понять, и это портит результат для полной окупаемости. Мне нужна помощь, чтобы понять это. Я добавил то, что у меня есть, для моего кода ниже:
#include <iostream>
#include <math.h>
using namespace std;
void mortgage::Mortgage() { // class object
double loanAmount = 0;
double annualInterestRate = 0;
double totalYearsToRepay = 0;
cout << "Enter the amount of the loan:";
cin >> loanAmount;
cout << "Enter annual interest rate in decimal term (example 0.075):";
cin >> annualInterestRate;
cout << "Enter the length of the loan in years:";
cin >> totalYearsToRepay;
cout << "Loan Amount: $" << fixed << loanAmount << endl;
cout << "Annual Interest Rate: $" << fixed << annualInterestRate << endl;
cout << "Total Years to Repay: $" << fixed << totalYearsToRepay << endl;
// Find monthly interest rate.
monthlyInterestRate=annualInterestRate /12;
// Find the total # of payments needed.
numberOfPayments = totalYearsToRepay* 12;
// Find power Factor.
powerFactor = pow(1.0 + monthlyInterestRate, numberOfPayments);
// Find the monthly payment.
monthlyPayment= (loanAmount * monthlyInterestRate)/(1-pow(1 + monthlyInterestRate, totalYearsToRepay));
cout << "Monthly Payment: $" << fixed << annualInterestRate << endl;
// Find the total pay back
totalPayBack = (monthlyPayment) * (numberOfPayments);
cout << "Total Pay Back: $" << fixed << totalPayBack << endl;
};
Вывод, который я должен получить для этого кода:
Сумма кредита: 50000,00 $
Годовая процентная ставка: 0,06250
Годы погашения: 10
Ежемесячный платеж: $ 561,40
Общая сумма возврата: $ 67368,06
Текущая выдача этого кода:
Сумма займа: $ 50000,000000
Годовой Процентная ставка: $ 0,062500
Общая сумма погашения: $ 10,000000
Ежемесячный платеж: $ 0,062500
Общая сумма возврата: $ -599859.388428