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.

Ive updated it to

#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";
    cout << "Dustin Boothe\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";

     do
          {          
          cout << setw(2) << day;
              for(double pay = 0.01; pay; pay = pow(pay, 2))
                 {

                  cout << setw(7) << fixed << pay << setprecision(2) << endl;
                 }

              day++;

              }while (day <= daysWorked);                                



    system("pause");
    return 0;

}

and getting this http://imgur.com/dWYCX9n in an infinite loop.

Thank you so much for the reply. I did actually get it all done. Just frustrating at times working through it.

New Code:

#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
    //initialize variables
    int daysWorked;
    int day = 1;
    double pay = .01;

    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";



              for(int x=1; x <= daysWorked; x++)
              {
                cout.flush();
                cout << setw(2) << day;

                cout << setw(20) << fixed << setprecision(2) <<  pay <<endl;
                balance += pay;
                pay += pay; 
                day++;


              }   
              cout << "----------------------";
              cout<<"\nTotal $"<<setw(15)<<balance<<endl<<endl<<endl<<endl;





    system("pause");
    return 0;

}

Took me out happy to execute the program into while and for loops. It is more intresting the logically perform the computer language to solve the program. You are really blow jobs, things are happen in the world elegant nice post. Thanks for sharing the knowledge. Thanks............

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.