1. ## C code question

Hello,

I'm trying to write a program in C that will prompt the user for the number of days in a month, and then ask how many pennies they will receive on the first day. I then have to tell them how much money they will have received by the end of the month if every day the amount of pennies they first received doubles (so if they got 1 penny on the first day, then they'll get 2 on the second, 4 on the third, etc.)

I'm having trouble figuring out how to find the total amount of pennies they received in the month. I can write a program for what they will receive on the last day of the month, just not the total amount. Can someone direct me in the right direction?

Thanks!

2. Imagine I gave you any arbitrary list of values, say [1, 10, 6, 7, 9] --- how would you find the sum then?
If you can calculate the amount received on each day it should be trivial; don't try to make this more complicated than it is.

3. This sounds suspiciously like a homework assignment. I mean, does anyone code something like this in their free time? =S

Also, post your effort before asking for help. Even if it's just setting up a loop, or some pseudo-code, it's better than nothing.

4. Originally Posted by memcpy
This sounds suspiciously like a homework assignment. I mean, does anyone code something like this in their free time? =S

Also, post your effort before asking for help. Even if it's just setting up a loop, or some pseudo-code, it's better than nothing.
I'm taking one of the free itunesU courses of programming (just starting out) and I'm working through one of the problem sets, but I'm stuck on this one and can't find a solution! So it is a 'homework' question, but I'm not actually in school, just personal interest.

I know the psudocode is something like this:

get number of days
get number of pennies
for (each day)
double pennies
update total
output total dollars and cents

I've got the first two steps, but I can't figure out how to keep on adding to a total without using an array or list or something like that. Any suggestions? Thanks!

5. Fair enough, try using this framework and tell me how it goes:

Code:
```uint64_t total = 0;
uint32_t temp = 0;
uint8_t day = 30;

while (day--) {
/* your code to get the power goes here, store it in temp */
total += temp;
}```

6. That works! Thanks a lot for your help!