Results 1 to 3 of 3

Thread: [RESOLVED] For loop example

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    37

    Resolved [RESOLVED] For loop example

    Hi, all

    I need a "For loop" source code to do like capital and interest calculation.

    for example:

    I put $100 in a bank, 7% interest rate, for 2 years, compounded annually.


    Thank you so much

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: For loop example

    Is this homework? Anyway heres a start

    VB Code:
    1. Dim Amount As Double = 100 '100$
    2.         Dim Interest As Single = 7 '7%
    3.         Dim Years As Integer = 2 'left in for 2 yrs
    4.         Dim OnePercent As Double
    5.         Dim InterestAdded As Double
    6.  
    7.         For i As Integer = 1 To Years
    8.             'loop through each yr
    9.             OnePercent = Amount / 100 'divide balance by 100 to give 1%
    10.             InterestAdded = OnePercent * Interest 'calculate interest earnings
    11.             Amount += InterestAdded 'add interest to amount
    12.         Next
    13.  
    14.         MessageBox.Show("After " & Years & " years at an interest rate of: " & Interest.ToString & "% your balance would be: " & Amount.ToString("c"))
    Last edited by the182guy; Feb 17th, 2007 at 12:16 PM.
    Chris

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    37

    Re: For loop example

    the182guy, thank you so much

    one more question, can I write such thing in vb:
    amount = (1 + interest) ^ year

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width