# Racking my brain

• 07-22-2011, 03:43 AM
beauti477
Racking my brain
I have been racking my brain for the past 2 1/2 hours trying to figure this out, I need to write a program to calculate and print the number of weeks that it will take to reach a total of one million dollars or greater if you are exponentially increases your money each week, meaning you have a penny the first week, then two pennies the next and four pennies the third week. Any ideas or help would be appreciated that will get me started. I know I have to write a while statement, but that is about all I know at this point.
• 07-22-2011, 03:47 AM
Junky
Inside the loop increment a count, increment money value. Surely it is not that hard to work out what the condition of the while loop is.
• 07-22-2011, 03:47 AM
Fubarable
What steps would you take if you had to solve it on paper without using Java? Often that's the best way to start a problem like this because it can get you to a workable algorithm.
• 07-22-2011, 07:55 AM
JosAH
Quote:

Originally Posted by beauti477
I have been racking my brain for the past 2 1/2 hours trying to figure this out, I need to write a program to calculate and print the number of weeks that it will take to reach a total of one million dollars or greater if you are exponentially increases your money each week, meaning you have a penny the first week, then two pennies the next and four pennies the third week. Any ideas or help would be appreciated that will get me started. I know I have to write a while statement, but that is about all I know at this point.

Are you allowed to solve the problem without using a loop? If so, note that the number of pennies is functionally dependent on the number of weeks, i.e. p= pow(2, w) where p and w are the number of pennies and the week number starting at zero. So, if you want to know w where p == 1000000 --> w = 2log(1000000), so w =~ 20.

kind regards,

Jos
• 07-22-2011, 07:58 AM
Junky
Bloody mathematicians!
• 07-22-2011, 08:17 AM
JosAH
Quote:

Originally Posted by Junky
Bloody mathematicians!

I only trust them as far as I can throw a rock at them.

kind regards,

Jos ;-)