单利计算有一些错误

Having some error in simple interest calculation

我在单利计算逻辑上犯了一些错误。 我能够计算第一行但无法使本金 = 新金额

Private Sub Calculate_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim p As Double = 50000
    Dim r As Double = 12.5
    Dim cf As Integer = 1
    Dim t As Integer = 12
    Dim a As Double = calcAmount(p, r)

    For index As Integer = 1 To t
        DataGridView1.Rows.Add(index, p, r, a)
        'changing p to new p
        p = a
    Next
End Sub
Function calcAmount(ByVal p As Double, ByVal r As Double) As Double
    Return p + p * r / 100
End Function

正如 LarsTech 在评论中所建议的,您可能希望在循环中:

For index As Integer = 1 To t
    DataGridView1.Rows.Add(index, p, r, a)
    'changing p to new p
    p = calcAmount(p, r)
Next