Pennies for Pay:
Write a program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the second day, four pennies the third day, and so on with the daily pay doubling each day the employee works. The program should ask the user for the number of days the employee worked during the month and should display a table showing how much the salary was for each day worked, as well as the total pay earned for the month. The output should be displayed in dollars with two decimal points, not in pennies.
The program I have written is below:
- Code: Select all
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int numDays;
double total = 0.0;
cout << "How many days have you worked this month? ";
cin >> numDays;
cout << "Day " << "Pay For That Day\n";
cout << "-------------------------------------\n\n";
for (int day = 1; day <= numDays; day++)
{
double daysPay = .01;
total += daysPay;
daysPay = daysPay * 2;
cout << fixed << showpoint << setprecision(2);
cout << day << " $" << daysPay << endl;
}
cout << fixed << showpoint << setprecision(2);
cout << "TOTAL $" << total << endl;
return 0;
}
No matter what number of days I enter (between 1 and 31) when asked how many days worked this month, every day is displayed with a pay of .02 and the total always comes out as the number I entered divided by 100. Any help with this is much appreciated. It's driving me insane.
