Doubling Pay Problem

As I continue to teach my self C++ I want to thank quirkyusername for the help with my earlier question. As for this one, I am learning how to write a program that doubles the pay (in pennies) for each day worked. I have the program working, but it starts the output at 2 pennies for day 1 instead of .01. Below is my code. Any help will once again be greatly appreciated.

//This program calculates how much a person earns over
//a period of time if the salary is a penny the first
//day, two pennies the second day and continues to double
//each day. The program should ask the user for the number
//of days. Then display a table showing how much the salary
//was each day and also the total pay at the end of the
//period. The output should be displayed in dollar amount.

#include <iostream>
#include <cmath>

using namespace std;

int main ()

{
int days, maxValue = 0;
float pay = .01;

cout <<"Please enter the number of days worked: ";
cin >> maxValue;

cout << "Day Pay" <<endl;
cout <<"_________________" <<endl;

for (days = 1; days <= maxValue; days++)
{
pay = ((pay) * (2));
cout <<days<<" "<<"$"<<pay<<endl;
}
return 0;
}
closed account (3hM2Nwbp)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Line 0  >    #include <iostream>
Line 1  >    #include <cmath>
Line 2  >
Line 3  >    using namespace std;
Line 4  >
Line 5  >    int main ()
Line 6  >    
Line 7  >    {
Line 8  >    int days, maxValue = 0;
Line 9  >    float pay = .01;
Line 10 >
Line 11 >        cout <<"Please enter the number of days worked: ";
Line 12 >        cin >> maxValue;
Line 13 >    
Line 14 >        cout << "Day Pay" <<endl;
Line 15 >        cout <<"_________________" <<endl;
Line 16 >    
Line 17 >        for (days = 1; days <= maxValue; days++)
Line 18 >        {
Line 19 >            pay = ((pay) * (2));
Line 20 >            cout <<days<<" "<<"$"<<pay<<endl;
Line 21 >        }
Line 22 >        return 0;
Line 23 >    }



On line 9, the variable 'pay' is set to 0.01
On line 19, the variable 'pay' is set to 'pay' * 2, which on the first iteration is 0.02
In order to make it start at 0.01, switch lines 19 and 20 around so the printing is before the doubling.
Topic archived. No new replies allowed.