Loop Question

Write your question here.

1
2
3
4
5
6
7
8
9
10
int i;
int wage=1

cout << "You will be paid a wage of $2 on your first day and have your wage doubled every day after that." << endl;
	for (int i = 2; i <= 20;i++)

	{
		wage = wage*i+2;
		cout << "On day " << i <<" your wage will be: $ " <<wage<< endl;
	} 


The point is to double 2$ every day for 20 days, I think my format( though I think I do not need wage) is correct but the math seems to be off, would like a hint on how to fix it.
Last edited on
Shameless bump, not sure if it's allowed. ):
the forum moves slowly here. If its on the first page, don't do this.

wage = 2;
for(I = 1; I < numdays; I++)
{
wage *=2;
... etc
}

if you don't need it daily, you can directly compute it.

wage = pow(2, dayinquestion);

youll want to go to an uint64_t before long. 20 isn't too bad, but it grows fast.
Last edited on
Topic archived. No new replies allowed.