我已经按照它应该的方式工作了,除了第一行的输出显示已经汇总的利息支付的运行总额,而不是与第一笔利息金额相同。因此,如果第一个月的利息为 1.05,则第一个月的总利息应为 1.05。第二个月将是 1.05 + 新的利息金额。现在它显示了上面的例子,2.10 作为第一个月的总数。我的逻辑哪里出错了?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Loan_Program
{
class Loan
{
//declare variables
private double LoanAmount, InterestRate;
private int LoanLength;
//Constructor of Loan class that takes amount, rate and years
public Loan(double amount, double rate, int years)
{
this.LoanAmount = amount;
this.InterestRate = (rate / 100.0) / 12.0;
this.LoanLength = years;
}
//returns the monnthly payment
public double GetMonthlyPayment()
{
int months = LoanLength * 12;
return (LoanAmount * InterestRate * Math.Pow(1 + InterestRate, months)) / (Math.Pow(1 + InterestRate, months) - 1);
}
//Calculates totl interterest paid and doubles it, then returns the amount
public double TotalInterestPaid(double number1,double number2)
{
double TotalInterest = number1+number2;
return TotalInterest;
}
//prints the amortization of Loan
public void LoanTable()
{
double monthlyPayment = GetMonthlyPayment();//calculates monthly payment
double principalPaid = 0;
double newBalance = 0;
double interestPaid = 0;
double principal = LoanAmount;
double totalinterest = 0;
//nonth, payment amount, principal paid, interest paid, total interest paid, balance
Console.WriteLine("{0,10}{1,10}{2,10}{3,10}{4,10}{5,10}", "Payment Number", "Payment Amt", "Interest Paid", "Principal paid","Balance Due","Total Interest Paid");
}
}
}
}
ITMISS
慕桂英3389331
明月笑刀无情
相关分类