adding in a loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zRaVeNk
    New Member
    • Sep 2006
    • 6

    adding in a loop

    i need help on how to take the numbers u get in a loop, and add them
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by zRaVeNk
    i need help on how to take the numbers u get in a loop, and add them
    Could you give a little more information?

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by willakawill
      Could you give a little more information?
      I 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...

      Code:
      Dim I as Long, J as Long
      FOR I = 1 To 10
        J = J + I
      Next
      You should end up with the following values...
      I = 11 (that's right, eleven - trust me on this)
      J = 55

      Perhaps this is something like what you were asking?

      Comment

      • nym11
        New Member
        • Dec 2006
        • 8

        #4
        Originally posted by Killer42
        I 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...

        Code:
        Dim I as Long, J as Long
        FOR I = 1 To 10
          J = J + I
        Next
        You should end up with the following values...
        I = 11 (that's right, eleven - trust me on this)
        J = 55

        Perhaps this is something like what you were asking?
        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.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by nym11
          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.
          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.

          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

          Working...