Results 1 to 6 of 6
  1. #1
    beauti477 is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Angry 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.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    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.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by beauti477 View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Bloody mathematicians!

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Junky View Post
    Bloody mathematicians!
    I only trust them as far as I can throw a rock at them.

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •