i need help on how to take the numbers u get in a loop, and add them
adding in a loop
Collapse
X
-
Could you give a little more information?Originally posted by zRaVeNki need help on how to take the numbers u get in a loop, and add them -
I have to agree - more information, pleaseOriginally posted by willakawillCould you give a little more information?
However, I'll try taking a "leap of faith"...
Create a variable to hold the result, and make sure it is zero before starting the loop. Then inside the loop, add the number to the result. For example...
You should end up with the following values...Code:Dim I as Long, J as Long FOR I = 1 To 10 J = J + I Next
I = 11 (that's right, eleven - trust me on this)
J = 55
Perhaps this is something like what you were asking?Comment
-
I need help with somthing similar. I have to make a program with the 12 days of christmas. i am using 2 arrays, one with text and one with numbers that i have to add both using loops. Pretty much what i have to do is make 2 arrays one with text and one with prices and have them put in a number for a day. then say they put in 5 i need it to display 5 golden rings, 4 french hens... etc back up to 1 and then i have to have under that the total cost of all the items displayed. say a golden ring is 10 dollars i need it to do 10*5 and then add that to the price of what 4 french hens are and all the way down the line until the total is displayed. then after that i have to have a line displaying a price for all 12 days together.Originally posted by Killer42I have to agree - more information, please
However, I'll try taking a "leap of faith"...
Create a variable to hold the result, and make sure it is zero before starting the loop. Then inside the loop, add the number to the result. For example...
You should end up with the following values...Code:Dim I as Long, J as Long FOR I = 1 To 10 J = J + I Next
I = 11 (that's right, eleven - trust me on this)
J = 55
Perhaps this is something like what you were asking?Comment
-
Um... I think I recall this thread, and someone suggested a two-dimensional array. You could also use two separate arrays. I'll throw together a little code snippet and see whether it helps.Originally posted by nym11I need help with somthing similar. I have to make a program with the 12 days of christmas. i am using 2 arrays, one with text and one with numbers that i have to add both using loops. Pretty much what i have to do is make 2 arrays one with text and one with prices and have them put in a number for a day. then say they put in 5 i need it to display 5 golden rings, 4 french hens... etc back up to 1 and then i have to have under that the total cost of all the items displayed. say a golden ring is 10 dollars i need it to do 10*5 and then add that to the price of what 4 french hens are and all the way down the line until the total is displayed. then after that i have to have a line displaying a price for all 12 days together.
Let's assume you have an array Description(1 to 12) As String containing the description of each day's item, and Price(1 To 12) As Single containing each item's individual price in dollars,
Code:' Assuming D = the selected day between 1 & 12 Dim I as Long, Total As Single For I = 1 To D Picture1.Print Description(I), Price(I) * I Total = Total + Price(I) * I Next Picture1.Print "Total",Total
Comment
Comment