I am doing some error in simple interest calculation logic. I am able to calculate for the first row but not able to make principal = the new amount
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
As suggested by LarsTech in the comments, you probably wanted INSIDE your loop:
For index As Integer = 1 To t
DataGridView1.Rows.Add(index, p, r, a)
'changing p to new p
p = calcAmount(p, r)
Next