2016-10-01 246 views
0

我有问题试图做一个计算器,准确计算存款加上每月增加的利息额。我不知道如何纳入一个循环,可以将每月存款添加到总存款,然后将总存款加总利息乘以总存款的利率/ 100/12。这是我到目前为止。对不起,VB是超级新手!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

那么,为什么你就不能增加你价值12,每个月?你不需要一个循环... – Codexer

+0

这就是我说的,但一个循环是需要一些奇怪的原因。这是一堂课。 – Sean

+0

也许你应该考虑在一个月的循环中包装该代码?敌人每年的敌人,然后在循环中使用你的代码。 –

回答

0

这就是我如何实现正确计算总利息和总存款的循环。

对于指数为整数= 1要intMonthsTotal步骤1 decTotalDeposits + = decMonthlyDeposit decTotalInterest + =(decTotalDeposits + decTotalInterest)*((decAnnualRate/100)/ 12)