I am in a fundamentals class for C++ and having a bit of an issue. I know the problem is not fully understanding. I am not looking for the answer but to get direction to better understand what I am doing wrong and how to fix it.
The Problem:
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.
Input Validation: Do not accept a number less than 1 or more than 31 for the number of days worked.
Requirements from the professor:
Use a "while" loop to validate "days worked". Use a "for" loop to calculate pay.
and should look like this: http://imgur.com/qwNDSmE
I am trying to get it to just get the daysWorked input and then display the pay correctly, after I was going to work on the total.
Here is what I have:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
//initialize variables
int daysWorked;
int day = 1;
double balance = 0;
//header info
cout << "Chapter 5 Homework\n\n\n";
//get user to enter days worked
cout << "How many days did the employee work this month?";
cin >> daysWorked;
while (! (daysWorked >=1 && daysWorked <=31))
{
cout << "NOTE: The number of days must be between 1 and 31." << endl;
cout << "Please re-enter days worked. ";
cin >> daysWorked;
}
cout << "Day Pay\n";
cout << "------------\n";
while (daysWorked >=1 && daysWorked <=31)
{
do
{
for(double pay = 0.01; pay; pay = pow(pay, 2))
{
cout << setw(2) << day << setw(7) << fixed << pay << setprecision(2) << endl;
}
day++;
}while (day <= daysWorked);
}
system("pause");
return 0;
}
and this is the current result. http://imgur.com/nyeDpEK
Thank you in advance for your help.