Hello I am not sure as to how to approach this problem,
The inventor of chess wanted his reward and he asked the emperor one grain of rice for the first square, 2 for the second , 4 for the third and so on...doubling for each of the 64 squares. How do i write a program to calculate how many squares are required to give the inventor at least 1000 grains of rice? and at least 1000,000,000?
how can i know the number of rice grains the inventor asked for?
Could someone explain to me the looping technique again.
You need to do the math by hand and think about this before trying to code it. What is the formula for the amount of rice for one specific square, say square number i ?
rice (i) = ?
Now, total rice is just a sum right? So if you know how to compute rice(i) you just need to do it in a loop accumulating the total.
Depending on the problem you want to solve you will use different a LOOP CONTROL VARIABLE (LCV).
In your first question the total amount of rice is the LCV: while( total < someMax )
You will also need a counter in your loop to track the current square.
I'll let you think about the second one, it is easier and should be done in a for loop.