我一直在为我的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