Not displaying counters correctly

Hello I'm VERY new to C++. This is supposed to display all the values of a person being paid .01 cent a day for the amount of days you input. the value of the salary on the corresponding day is found using 2 ^ (n-1) where n is the amount of days.


However it only displays the salary of the final day repeated for each day. Instead of displaying the salary for each individual day. It's not incrementing from n=1.

I'm clueless. Anything to help me along is greatly appreciated.

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
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
        const int minNumber = 1;
        int num, maxNumber;
        float exponent = 2, n;
        double total;

        cout << "How many days did you work?" ;
        cin >> maxNumber;

        cout << " days Salary\n ";
        cout << "----------------\n";

                n = (maxNumber-1);

        for (int num = minNumber; num <= maxNumber; num++)

        cout << num << "\t\t" << pow ( exponent , n ) * .01 << endl;

        return 0;
}

Last edited on
If you want to display how much they earned on each day, it would be something like
1
2
for(int num = minNumber; num <= maxNumber; num++)
    cout << num << "\t\t" << num * .01 << endl;


Since you're displaying how much they earned each day, you can just simply multiply the current day by .01, and the for loop takes care of increasing the days, so there is no need to calculate how much they earn on the last day with the 2^(n-1) method.
Last edited on
Thank You So Much!

that was driving me crazy :)

I'm determined to get C++ though.
Topic archived. No new replies allowed.