Pennies for pay homework

So I have to solve this using a For loop. I have to make it display a message once it hits 1 million dollars which is 100,000,000 pennies but im not sure how to implement that. Also I need it to count up to 64 days but it only goes to 63. If anyone could help that would be great!thanks

 ``1234567891011121314151617`` `````` #include using namespace std; int main ( ) { long long i; long long j; cout<< "Day Daily Payout(in Cents)" << endl; cout<< "----------------------------------" << endl; for( i = 1,j = 1; i<=64, j>=0; i= i++, j = j*2) cout << i << " " << j << endl; return 0; } ``````
start your counter at 0. and

 ``1234567`` ``````for (i = 0; i <= 64; i++) { while (j < 100000000) { j = j * 2; } cout << i << " " << j << endl;``````
 ``12`` ``````int i; unsigned long long j;``````
When i use unsigned long long the program seems to count from 1 to infinity, and just keeps printing out numbers.

I tried putting in that while loop but I need it to look something like this http://gyazo.com/7b946464cbe36ccb23a3de664a3239b9 except with a message only printing out once, once it hits 100million pennies, so that would be after day 28.
I forgot, your for loop should look like this.
 `` `` ``for( i = 1,j = 1; i<=64; i= i++, j = j*2)``
:O now it counts to 64 thanks! Any idea on how to get it to print out one message once it hits day 28?
 ``123`` ``````bool millionReached = false; if(j > 100000000 && !millionReached)``````
not sure how to fix the last output
 ``123456789101112131415161718192021222324`` ``````#include using namespace std; int main ( ) { long long i; long long j; long long x = 0; cout<< "Day Daily Payout(in Cents)" << endl; cout<< "----------------------------------" << endl; for( i = 1, j = 1; i<=64; i++, j = j*2) { if (j > 100000000) { x++; } while (x == 1) { cout << "One Million!" << endl; x++; } cout << i << " " << j << endl; } return 0; }``````
unsigned long long j; fixed the last one

Thanks for the help guys, I get how to do it now. Many thanks

what's wrong with the last output?

 ``123456789101112131415`` ``````int i; unsigned long long j; bool millionReached = false; for(i = 1, j = 1; i <= 64; i++, j*=2) { if(!millionReached && j > 100000000) { cout << "One Million!\n"; millionReached = true; } cout << i << "\t\t\t << j << endl; } return 0; ``````
Last edited on
on the code i did it output a negative number for the last output
`unsigned long long j;` fixed the last output
Topic archived. No new replies allowed.