|
-
Feb 17th, 2007, 11:39 AM
#1
Thread Starter
Member
[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
-
Feb 17th, 2007, 11:50 AM
#2
Re: For loop example
Is this homework? Anyway heres a start
VB Code:
Dim Amount As Double = 100 '100$
Dim Interest As Single = 7 '7%
Dim Years As Integer = 2 'left in for 2 yrs
Dim OnePercent As Double
Dim InterestAdded As Double
For i As Integer = 1 To Years
'loop through each yr
OnePercent = Amount / 100 'divide balance by 100 to give 1%
InterestAdded = OnePercent * Interest 'calculate interest earnings
Amount += InterestAdded 'add interest to amount
Next
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
-
Feb 18th, 2007, 02:33 PM
#3
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|