Results 1 to 6 of 6
Thread: Racking my brain
 07222011, 03:43 AM #1Member
 Join Date
 Jul 2011
 Posts
 5
 Rep Power
 0
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.
 07222011, 03:47 AM #2
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.

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.
 07222011, 07:55 AM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
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,
JosBuild a wall around Donald Trump; I'll pay for it.
 07222011, 07:58 AM #5
Bloody mathematicians!
 07222011, 08:17 AM #6
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
Bookmarks