There's a logic error right there. The comma operator can be understood as, "do then, and do this". But when you want to evaluate the result of an expression, only the last value counts.
Example:
int x = (4, 7, 3) ;
What value will be assigned to x? The answer in this example is 3 since that is the right-most expression.
Now look at the condition used in the for loop:
for (day = 1, pennies = 1; day <= days, pennies <= days; day++, pennies*2)
You see what happens here? It is as if you had put just:
for (day = 1, pennies = 1; pennies <= days; day++, pennies*2)
I think that is not what you want. the loop should be checking only the other condition,
day <= days
and the second part should be deleted, it is superfluous.
There is another error too. Look at this code:
day++, pennies*2
Now there is no problem with having more than one expression here, that's ok.
However,
day++
means add 1 to the current value of day and store the result in day.
But
pennies*2
means multiply the current value of pennies by 2, and don't store the result anywhere. It should be either:
pennies = pennies*2
or more concisely,
pennies*=2
So now the complete line reads like this:
|
for (day = 1, pennies = 1; day <= days; day++, pennies*=2)
|
See the tutorial page for help with operators, in particular compound assignment and the comma operator.
http://www.cplusplus.com/doc/tutorial/operators/