# Help with code for interest calculation formula visual basic 2008

Im having problems with getting the correct formula for this assignment. I did what the book says and its not working. I have to enter a principal and then in the multiline text box I have to have one column with the rate(%) which are 5,6,7,8,9 and 10 and then the other column has to be the amount after 10 years. It says the interest calculation formula is a=p(1+r)^n. This is what I got so far and nothing is appearing in my multiline text box.
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
' Declare Variables
Dim Principal As Decimal
Dim Rate As Double
Dim Amount As Decimal
Dim Output As String

' Retrieve User Input
Principal = Val(principalTextBox.Text)
Output = ResultTextBox.Text

Output = "Rate(%)" & ControlChars.Tab & ControlChars.Tab & "Amount after 10 years" & ControlChars.CrLf

' Calculate Amount
For years As Integer = 5 To 10
Amount = _
Principal * ((1 + Rate) ^ 10)
Output = ("5" & ControlChars.Tab & ControlChars.Tab & _
String.Format("{0:C}", Amount) & ControlChars.CrLf)
Next

End Sub

Any help please im getting frustrated.
###### Who is Participating?

x

Commented:
That's what you instructed it to print on:

Output = Output & ("5" & ControlChars.Tab & ControlChars.Tab & _
String.Format("{0:C}", Amount) & ControlChars.CrLf)

Try this:

``````Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
' Declare Variables
Dim Principal As Decimal
Dim Rate As Double
Dim Amount As Decimal
Dim Output As String

' Retrieve User Input
Principal = Val(principalTextBox.Text)
Output = ResultTextBox.Text & ControlChars.CrLf

Output = Output & "Rate(%)" & ControlChars.Tab & ControlChars.Tab & "Amount after 10 years" & ControlChars.CrLf

' Calculate Amount
For years As Integer = 5 To 10
Rate = years / 100
Amount = _
Principal * ((1 + Rate) ^ 10)
Output = Output & (years.ToString() & ControlChars.Tab & ControlChars.Tab & _
String.Format("{0:C}", Amount) & ControlChars.CrLf)
Next

ResultTextBox.Text = Output

End Sub
``````
0

Commented:
Try this:

``````Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
' Declare Variables
Dim Principal As Decimal
Dim Rate As Double
Dim Amount As Decimal
Dim Output As String

' Retrieve User Input
Principal = Val(principalTextBox.Text)
Output = ResultTextBox.Text & ControlChars.CrLf

Output = Output & "Rate(%)" & ControlChars.Tab & ControlChars.Tab & "Amount after 10 years" & ControlChars.CrLf

' Calculate Amount
For years As Integer = 5 To 10
Amount = _
Principal * ((1 + Rate) ^ 10)
Output = Output & ("5" & ControlChars.Tab & ControlChars.Tab & _
String.Format("{0:C}", Amount) & ControlChars.CrLf)
Next

ResultTextBox.Text = Output

End Sub
``````
0

Author Commented:
It calculated but now the problem is it has one column of all 5's and the other column is the same number too
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.