Hi! I have For Loop problem!! Thanks

I was ask to write a program that do the following:

You start the job with 1 cent salary, and each day after you earn double the previous days salary.

The user will tell you how many days they worked.

You will tell them their pay for each day and the total salary they earned at the end of the number of days.

Format the output as money
Use a for loop!


ok I did some of the code, but when I try to do the math, I dont get it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
   double CENT=1;
    
    int days=0;
    
    int counter=0;
    
    double total=0;
    
    cout<<"How many days are you working?:"<<endl;
    cin>>days;
    
    
   
 
            for(counter = 1 ; counter <= days;counter++)
            {
               
              /* Here is the problem I dont know how to do the math so I can get this to work ... 
*/

               total=(counter* CENT*2  );
               
               

          //I get this part to work..
                cout <<"On day "<<counter<<" you recive:"<<" $ "<<total<<endl;     
                
              }    
                
      
    

    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}



Thanks, I just need a hint . Thanks
double total =1;
int days = 0;

cout << "input days: ";
cin >> days;


for (int count = 1; count < days; count++)
total += total;

I think will work.
1
2
3
4
5
6
for(counter = 1 ; counter <= days ; counter++)
{
   total = CENT;
   CENT = CENT*2;
   cout << "On day "<<counter<<" you receive:"<<" $ "<<total<<endl;
}


On day 1 you receive: $ 1
On day 2 you receive: $ 2
On day 3 you receive: $ 4
On day 4 you receive: $ 8
On day 5 you receive: $ 16
On day 6 you receive: $ 32


Basically you just set the value of CENT to total then double CENT. This should work just fine.
Slambofett thanks , how can I add up all of those number so I can have the total ? Thank you
That's basically what I said...

Thank you too, Have a good night..
Topic archived. No new replies allowed.