我一直在爲我的C++類開發一個簡單的貸款計算器程序,但我不能爲我的生活找出我要出錯的地方。除計算貸款的總利息外,整個計劃按預期運作。我覺得這裏的答案很簡單,但我看不到它。計算貸款計算器程序總利息的問題(C++)
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int numberOfPayments;
double monthlyInterestRate;
double Loan;
double monthlyPayment;
double annualInterestRate;
double interestTotal;
double loanTotal;
cout << "Enter the loan amount (principal) --> ";
cin >> Loan;
cout << "Enter the YEARLY interest rate as a percentage --> ";
cin >> annualInterestRate;
cout << "Enter the number of payments --> ";
cin >> numberOfPayments;
monthlyInterestRate = annualInterestRate/12;
monthlyInterestRate = monthlyInterestRate/100;
monthlyPayment = (monthlyInterestRate) * pow((1 + monthlyInterestRate), numberOfPayments)/(pow((1 + monthlyInterestRate), numberOfPayments) - 1) * Loan; // Amount of monthly payments
loanTotal = (monthlyPayment * numberOfPayments); // Total amount due for loan
interestTotal = monthlyInterestRate * numberOfPayments * monthlyPayment;
cout << monthlyInterestRate << endl;
cout << "Loan Amount: $" << setw(8) << Loan << endl;
cout << "Yearly Interest Rate: " << setw(8) << annualInterestRate << "%" << endl;
cout << "Number of Payments: " << setw(8) << numberOfPayments << endl;
cout << "Monthly Payment: $" << setw(8) << setprecision(5) << monthlyPayment << endl;
cout << "Amount Paid Back: $" << setw(8) << setprecision(7) << loanTotal << endl;
cout << "Interest Paid: $" << setw(8) << setprecision(5) << interestTotal << endl;
cout << "\n\nProgram Over";
cout << "\n\n\nPress Enter to end -->";
cin.ignore();
cin.get();
return 0;
}
首先錯誤在那裏:'monthlyInterestRate = annualInterestRate/12;'你複合?什麼類型的「年度」利益呢? – 2014-02-06 21:40:44
我不確定我瞭解你的問題。如果有幫助,它應該使用簡單的興趣。 – user3281514
什麼是印刷,你期望它打印什麼?至少每月付款的計算對我來說很合適。 – TypeIA