pow function problem

Hi, I am currently taking an intro class to C++. Our teacher wants us to use any method to figure out how many weeks it will take to become a millionaire if.... on week 1, we are given 1 penny... on week 2, we are given 2 pennies... on week 3, we are given 4 pennies. We have to use a loop, so I don't think log functions are acceptable.

This is what I have so far (see below). It seems like it should work, but nothing happens when I run the program -- it just seems like the program is 'thinking' forever, without outputting anything to the console. To exit, I have to CTRL-C it. Any hints are very welcome! Thank you!

this uses the function... y = 2^(n-1)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;


int main()
{
    double weeks = 1;
    double pennies = pow(2.0, weeks-1);
    double dollars = (pennies / 100.0);


  while (true)
    {
      if (dollars < 10000000)
        weeks++;
      else break;
    }

  cout << "In " << weeks << " weeks, I will be a millionaire!" << endl;

  return 0;
}
Incrementing "weeks" would not change the value of "pennis", and therefore not change the value of "dollars". You would need to recalculate "pennies" and "dollars" inside of the while loop for this to work.
Last edited on
thank you! works fine now! :)
Topic archived. No new replies allowed.