我在尝试制作能够准确计算存款的计算器以及每月添加的利息金额时遇到问题。我不知道如何加入一个可以将每月存款添加到总存款的循环,然后将总存款加上总利息乘以利率/ 100/12到总存款。这是我到目前为止所拥有的。对不起,我是VB的新手!
Dim intMonthlyDeposit As Interger
Dim intMonthsTotal As Integer
Dim intAnnualRate As Interget
Dim decTotalDeposits As Decimal
Dim decTotalInterest As Decimal
Dim decTotalTotal As Decimal
Try
intMonthlyDeposit = CInt(txtMonthlyDeposits.Text)
intMonthsTotal = CInt(txtMonths.Text)
decAnnualRate = CDec(txtAnnualRate.Text)
decTotalDeposits = 0
decTotalInterest = 0
decTotalTotal = 0
decTotalDeposits = decMonthlyDeposit * intMonthsTotal
decTotalInterest = decTotalDeposits * (decAnnualRate / 100)
decTotalTotal = decTotalDeposits + decTotalInterest
lblTotDeposit.Text = decTotalDeposits.ToString("C")
lblTot.Text = decTotalTotal.ToString("C")
lblTotInterest.Text = decTotalInterest.ToString("C")
Catch ex As Exception
MsgBox("Enter a Valid Number")
End Try
End Sub
答案 0 :(得分:0)
这就是我如何实现正确计算总利息和总存款的循环。
对于索引As Integer = 1到intMonthsTotal Step 1 decTotalDeposits + = decMonthlyDeposit decTotalInterest + =(decTotalDeposits + decTotalInterest)*((decAnnualRate / 100)/ 12)