Link to home
Start Free TrialLog in
Avatar of goldfingerpunk
goldfingerpunk

asked on

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

        ' Set Output Header
        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.
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

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

        ' Set Output Header
        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

Open in new window

Avatar of goldfingerpunk
goldfingerpunk

ASKER

It calculated but now the problem is it has one column of all 5's and the other column is the same number too
ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial