Loop Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ksull
    New Member
    • Apr 2010
    • 1

    #1

    Loop Problem

    I have to write a Visual Basic program that calculates the actual amount of rice using a loop. Each loop iteration is the traversal of one square on the chess board. A grain of rice weighs app. 0.000055116 pounds. Your program should start its calculation upon a button click and print the weight of the rice placed on the 64th square in pounds. The data type you will need to use for the rice count is ULong (this is an Integer type number that can hold large positive values).

    I have no idea where to begin or how to write this code. Please help
  • vb5prgrmr
    Recognized Expert Contributor
    • Oct 2009
    • 305

    #2
    you need to loop from 1 to 64 in a for loop and do a simple addition within the loop (result = weightvalue + result)...



    Good Luck

    Comment

    • smartchap
      New Member
      • Dec 2007
      • 236

      #3
      No. of grains in a particular square will be equal to 2^(Square Number - 1), i.e. for first square it will be 2^(1-1)=2^0=1, for second 2^(2-1)=2,..., for 64th square 2^(64-1) = 9.22337E+18 i.e. = 922337203685478 0000.00 and to get in pounds multiply number of grains in a particular square with weight of one grain , i.e. 0.000055116. Thus u get the result. To get total weight of rice on chess board add weight of rice in all squares.

      Comment

      Working...