HELP! program

Hello, I am new to C++ programming and to this forum. I am doing a program for class and I just can't figure out what I am doing wrong.

The program is supposed to calculates the amount a person would earn over a period of time if his or her salary were one penny the first day, two pennies the second day, and so on doubling each day.
The output should look like this.

Day Pay
================
1 $0.01
2 $0.02
3 $0.04
4 $0.08
5 $0.16
Your total pay is $0.31

Instead it is coming out like this

Day Pay
================
1 $0.02
2 $0.04
3 $0.08
4 $0.16
5 $0.32
Your total pay is $0.31


this is my code.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int Days;
double total = 0.0;
double daysPay = 0.01;

cout << "How many days have you worked this month? ";
cin >> Days;
cout << "Day " << "Pay For That Day\n";
cout << "-------------------------------------\n\n";

for (int day = 1; day <= Days; day++)

{

(total += daysPay);
(daysPay = daysPay * 2);

cout << day << " $" << daysPay << endl;
}

cout << "TOTAL $" << total << endl;

return 0;
}
@birdy08

Woo hoo!!.. An easy fix, finally.

You just have to move one line. Move cout << day << " $" << daysPay << endl;, to just after the first curly bracket in the for loop. Right now, your printing the amount an amount for the next day, rather than before, but your adding the total up for the correct day. That's why your total is correct, but the output, isn't.
Last edited on
Thank you very much! Just could not see it! so simple!
Thanks!!!!
Topic archived. No new replies allowed.