need help my (employee payroll program using structures)does not show all data
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 4 1234 LastLast
Results 1 to 15 of 50

Thread: need help my (employee payroll program using structures)does not show all data

  1. #1
    Join Date
    Nov 2013
    Posts
    49

    Question need help my (employee payroll program using structures)does not show all data

    Im writing a employee payroll program using structures. My program is running but its only showing some of the data.
    HERES MY CODE

    Code:
    #include <iostream>
    #include <cstdio>
    #include <fstream>
    #include <string>
    #include <iomanip>
    #include <cstring>
    using namespace std;
    const int SZ = 20; // size of arrays to hold scores
    struct payrollStruct
    {
    	string firstname; // first name of golfer
    	string lastname; // last name of golfers
            string empID; 
           // int hrs;
    };
    void tellUser();
    int readInput(payrollStruct []);
    void bubbleSort(payrollStruct [], int);
    int writeReport(payrollStruct [], int);
    void swap(payrollStruct *, payrollStruct *);
    int main()
    {
        int i, code, ret; // counter
        payrollStruct employee[SZ]; // array of golfers and data
        int numemp; // total number of golfers
        tellUser(); // tell user what program does 
        numemp= readInput(employee);
        cout << "There were " << numemp << " golfers\n\n";
        if (numemp < 1)
        {
           cout << "Program ending\n\n";
           code = 1;
        }
        else
        {
           // calculate total and average for each golfer
           cout << "calculating average and totals\n";
           // sort golfers
           cout << "Sorting the golfers in order with the winner first\n";
    
           bubbleSort(employee, numemp);
           code =  writeReport(employee, numemp);
       }
       return code;
    }
    /* **************************************************************************
    * output report
    * this function writes data to screen and file
    * input parameters: array of golfStructs and number golfers
    * ouput written to screen and file
    -
    womengolfreport.txt
    * ************************************************************************* */
    int writeReport(payrollStruct emp[],int numE)
    {
        int i; // counter
        ofstream outputFile; // output file
        // open report file and write output data ********************
        cout << "Report being written to file payroll.txt\n";
        outputFile.open("payroll.txt"); // output file
        if (outputFile.fail())
        {  
           cout << "output file did NOT open\n";
           cout << "output will only be sent to the screen\n";
           cout << "\n\nGolfer Name Pos rnd1 rnd2 rnd3 rnd4 total average\n";
           for ( i=0; i < numE; i++)
           {
           		 //emp[i].place = (i + 1);
    		 cout << emp[i].firstname << " ";
    		 cout << emp[i].lastname << " ";
    		 cout << emp[i].empID << "\n";// << emp[i].hrs << " ";
    		// cout << emp[i].rate << " ";// << glf[i].rounnd[3] << " ";
    		// cout << glf[i].totalScore << " ";
    		// cout << glf[i].averageScore << "\n";
           }
        }	 // end if file did not open
        else
        {
    	cout <<"First          Last       Employee     Hours        Rate      Regular    Overtime    Gross\n";  //table of employees payroll data sheet to the screen
            cout <<"Name           Name        Number      Worked      of Pay       Pay        Pay        Pay\n";
            cout <<"===========================================================================================\n";
            outputFile <<"First          Last        Employee     Hours       Rate      Regular    Overtime    Gross\n";//table of employees payroll data sheet to txt file
            outputFile <<"Name           Name         Number      Worked     of Pay      Pay        Pay        Pay\n";
            outputFile <<"=========================================================================================\n";
                 // loop to print report of golfers ********************
                 for ( i=0; i < numE; i++)
                 {
    	//	emp[i].place = (i + 1);
    	        //outpute << setw(12);
                    //outputFile << setw(9) << fixed << left << glf[i].lastname << " ";
    		//outputFile << setw(9) << fixed << left << glf[i].firstname << " ";
    		//outputFile << glf[i].place << " ";
    		//outputFile << setw(4) << fixed << left << glf[i].rounnd[0] << " ";
                    //outputFile << setw(4) << fixed << left << glf[i].rounnd[1] << " ";
    		//outputFile << setw(4) << fixed << left << glf[i].rounnd[2] << " ";
                    //outputFile << setw(4) << fixed << left << glf[i].rounnd[3] << " ";
    		//outputFile << setw(6) << fixed << left << glf[i].totalScore << " ";
    		//outputFile << setw(7) << fixed << setprecision(2) << glf[i].averageScore << "\n";
    				
                    cout << fixed << left <<  emp[i].lastname << setw(10) << emp[i].firstname;
                    cout << emp[i].empID << "\n";
    	    }		
    	    outputFile.close();
                cout << "Output file closed\n\n";
        } // end else output file open
        return 0;
    } // end of writeReport **************************************
    /* *********************************************************
    * bubble sort with flag
    * this function sorts golfers into order by total score
    * the winner is first with the lowest score, alphabetical
    * order when scores match
    * input parameters: array of golfStruct and number of golfers
    * in that array
    * ouput: those array items are now sorted
    *************************************************************** */
    void bubbleSort(payrollStruct emp[], int numE)
    {
    	bool swapmade = false; // when true a swap was made in this pass
    	int i, lastpos; // last position to look for correct order
    	// sort the golfers from winner to loser
        cout << "sorting golfers with winner first\n";
        lastpos = numE;
        do
        {
    	lastpos--;
    	swapmade = false;
    	for ( i = 0; i < lastpos; i++)
    	{
    	    if ( emp[i].lastname > emp[i+1].lastname) // they are in the wrong order
    	    { // swap all items here
    	      	swap(emp[i], emp[i+1]);
    	        swapmade = true;
    	    {
    	} // end of for loop
         } while(swapmade); // end of do loop
    }
    /* *********************************************************
    * readInput
    i* This function reads golfer data from a file "women.txt"
    * It stores the first and last names of golfers and 4 rounds
    * of golf scores for each golfer in an array of structures
    * input: first and last names, 4 golf scores each person
    * passes back: array of golfer data in structure
    *
    returns: number of golfers
    *************************************************************** */
    int readInput(payrollStruct  emp[])
    {
        ifstream inputFile; // input filename in program
        int numEmp; // number employees 
        int i;// counter
        // open file and read input from file golfers.txt
        inputFile.open("employees2.txt"); 
        if (inputFile.fail())
        {
    	cout << "Error opening file women.txt\n\n";
            cout << "end of program\n\n";
        	return 0;
        }
        else 
        {
            i = 0; // golfer number for array	
    	while ( ( i < SZ) && (inputFile >> emp[i].empID))
    	{ // there is a line of data to read and array has rooms
    		inputFile >> emp[i].lastname; // read last name of golfer
                    inputFile >> emp[i].firstname; // read first name of golfer
                    i++; // ready for the next golfer
    	} // end while
    	numEmp = i; // number golfers
    	inputFile.close(); // close the file after reading it
    	cout << "input file closed\n\n";
    	return numEmp; // return number golfers read in file
        } // end if else
    } // end function readInput
    /* ***************************************************************
    * function tellUser
    * it tells the user what the program does
    * it prints output to the screen
    * input: none output: tells user on s
    creen what program does
    * returns: none
    ****************************************************** */
    void tellUser()
    {
    	cout << "This program reads a file called employees2.txt,\n";
    	cout << "and it calculates the total and average for each golfer.\n";
    	cout << "golfers are sorted into order with winner first and loser last.\n";
    	cout << "output is written to the screen. and to an output file\n";
    	cout << "It uses an array of structures to store the data\n";
    }
    /*************************************
    * Function swap
    * this function swaps to golfStructs
    * input parameters: two golf structs
    * output parameters: now swapped with each other
    ****************************/
    void swap(payrollStruct &empa, payrollStruct &empb)
    {
    	payrollStruct temp; // place to store one golfer data
    	temp = empb;
    	empb = empa;
    	empa = temp;
    }
    and it doesnt show anything from txt file
    Code:
    40.0   10.00 A1234 Jane Adams
    50.0   10.00 L8765 Mary Lincoln
    25.5   10.85 W7654 Martha Washington
    52.0   15.75 A9876 John Adams
    45.0   25.00 W1235 George Washington
    40.25  55.00 L9087 Abraham Lincoln
    30.0    9.75 T9876 William Tell
    42.5   12.50 M7654 Missy Muffett
    30.0   10.00 P8765 Peter Piper
    45.0   15.00 T8765 Zachary Taylor
    50.75  50.00 F5432 Millard Fillmore
    40.0   45.50 P3452 Franklin Pierce

  2. #2
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,621

    Re: need help my (employee payroll program using structures)does not show all data

    Sorry but there is too much code and too little evidence that you tried to solve the problem yourself.

    Use a debugger to run one line of code at a time, and check the values of the variables while you run.

    If you still have a question after that, you are very welcome to ask.
    Nobody cares how it works as long as it works

  3. #3
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    Re: need help my (employee payroll program using structures)does not show all data

    Is this a payroll program or a golf program?

    It would be easier to read you code if you formatted it properly before posting. It is also easier to spot problems.

    You have a bracket issue in bubble sort.

    Also a problem with swap function declaration and definiton.

    You need to learn how to debug your programs properly using the debugger to determine where it deviates from what was expected according to the program design.
    Last edited by 2kaud; December 11th, 2013 at 04:58 PM.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    Join Date
    Nov 2013
    Posts
    49

    Re: need help my (employee payroll program using structures)does not show all data

    im using linux and it does not give any errors

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: need help my (employee payroll program using structures)does not show all data

    Quote Originally Posted by Krrish1 View Post
    im using linux and it does not give any errors
    Clearly it has errors, or you wouldn't be here. The debugger will help you find logic errors.

    This is a Visual C++ forum, so your question is off-topic here anyway.

  6. #6
    Join Date
    Nov 2013
    Posts
    49

    Question Re: need help my (employee payroll program using structures)does not show all data

    Now my program runs when i vomment out the following:
    cout << setw(13) << fixed << left << emp[i].lastname << " " <<setw(12) << emp[i].firstname << " ";
    cout << setw(11) << emp[i].empID << " " << setw(11) << fixed << setprecision(2) << emp[i].hoursworked<< " ";
    cout << setw(8) << fixed << setprecision(2) << emp[i].hourlyrate << "\n";// << regularpay[i] << " ";
    // cout << overtimepay[i] << " " << grosspay[i] << " ";

    and also can i get help on how to calculate only gross pay
    and this is what i get on screen after executing
    Code:
    First          Last       Employee     Hours        Rate      Regular    Overtime    Gross
    Name           Name        Number      Worked      of Pay       Pay        Pay        Pay
    ===========================================================================================
    Adams         Jane         A1234       40.00       10.00
    Adams         John         A9876       52.00       15.75
    Buchanan      James        B7612       23.00       48.55
    Cleveland     Grover       C9856       38.50       25.00
    Fillmore      Millard      F5432       50.75       50.00
    Grant         Ulysses      G5612       60.50       35.00
    Harrison      Benjamin     H5431       30.50       28.50
    Hayes         Rutherford   H6542       45.50       35.50
    Lincoln       Mary         L8765       50.00       10.00
    Lincoln       Abraham      L9087       40.25       55.00
    Muffett       Missy        M7654       42.50       12.50
    Pierce        Franklin     P3452       40.00       45.50
    Piper         Peter        P8765       30.00       10.00
    Roosevelt     Theodore     R1234       56.50       45.25
    Roosevelt     Elenor       R2345       25.00       48.75
    Taylor        Zachary      T8765       45.00       15.00
    Tell          William      T9876       30.00       9.75
    VanBuren      Martin       V4532       42.00       40.75
    Washington    Martha       W7654       25.50       10.85
    Washington    George       W1235       45.00       25.00
    ============================================================================================
                            Total Gross Pay                                               CAL GROSS PAY ONLY

  7. #7
    Join Date
    Nov 2013
    Posts
    49

    Re: need help my (employee payroll program using structures)does not show all data

    ok let me try on visual c++

  8. #8
    Join Date
    Nov 2013
    Posts
    49

    Question Re: need help my (employee payroll program using structures)does not show all data

    Now my program runs when i vomment out the following:
    cout << setw(13) << fixed << left << emp[i].lastname << " " <<setw(12) << emp[i].firstname << " ";
    cout << setw(11) << emp[i].empID << " " << setw(11) << fixed << setprecision(2) << emp[i].hoursworked<< " ";
    cout << setw(8) << fixed << setprecision(2) << emp[i].hourlyrate << "\n";// << regularpay[i] << " ";
    // cout << overtimepay[i] << " " << grosspay[i] << " ";


    and also can i get help on how to calculate only gross pay
    and this is what i get on screen after executing

    Code:
    First          Last       Employee     Hours        Rate      Regular    Overtime    Gross
    Name           Name        Number      Worked      of Pay       Pay        Pay        Pay
    ===========================================================================================
    Adams         Jane         A1234       40.00       10.00
    Adams         John         A9876       52.00       15.75
    Buchanan      James        B7612       23.00       48.55
    Cleveland     Grover       C9856       38.50       25.00
    Fillmore      Millard      F5432       50.75       50.00
    Grant         Ulysses      G5612       60.50       35.00
    Harrison      Benjamin     H5431       30.50       28.50
    Hayes         Rutherford   H6542       45.50       35.50
    Lincoln       Mary         L8765       50.00       10.00
    Lincoln       Abraham      L9087       40.25       55.00
    Muffett       Missy        M7654       42.50       12.50
    Pierce        Franklin     P3452       40.00       45.50
    Piper         Peter        P8765       30.00       10.00
    Roosevelt     Theodore     R1234       56.50       45.25
    Roosevelt     Elenor       R2345       25.00       48.75
    Taylor        Zachary      T8765       45.00       15.00
    Tell          William      T9876       30.00       9.75
    VanBuren      Martin       V4532       42.00       40.75
    Washington    Martha       W7654       25.50       10.85
    Washington    George       W1235       45.00       25.00
    ============================================================================================
                            Total Gross Pay                                               CAL GROSS PAY ONLY

  9. #9
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    Re: need help my (employee payroll program using structures)does not show all data

    Now my program runs when i vomment out the following:
    cout << setw(13) << fixed << left << emp[i].lastname << " " <<setw(12) << emp[i].firstname << " ";
    cout << setw(11) << emp[i].empID << " " << setw(11) << fixed << setprecision(2) << emp[i].hoursworked<< " ";
    cout << setw(8) << fixed << setprecision(2) << emp[i].hourlyrate << "\n";// << regularpay[i] << " ";
    // cout << overtimepay[i] << " " << grosspay[i] << " ";
    Those lines are not in the program you posted in post #1 so the posted program is not the one you are using. If you wish further advice, I suggest you post the actual program with which you are having the problem.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  10. #10
    Join Date
    Nov 2013
    Posts
    49

    Question Re: need help my (employee payroll program using structures)does not show all data

    THAT WAS THE PART I UPDATED and also can i get help on how to calculate only gross pay
    HERE IS THE FULL VERSION OF THE CODE:

    Code:
    #include <iostream>
    #include <cstdio>
    #include <fstream>
    #include <string>
    #include <iomanip>
    #include <cstring>
    using namespace std;
    const int SZ = 20;          // size of arrays to hold employee
    struct payrollStruct        // strucute of employees
    {
          double hoursworked;   // employess hours worked
          double hourlyrate;          // employees rate of pay
          string empID;         // employee ID
          string firstname;     // first name of employee
          string lastname;      // last name of employee
          //double regularpay;       // total of those 4 rounds
         // double averageScore;  // average of 4 rounds of score
        
    };
    void tellUser();
    int readInput(payrollStruct []);
    void bubbleSort(payrollStruct [], int);
    void swap(payrollStruct *, payrollStruct *);
    void findregularhours(payrollStruct [], int[], int);
    void findregularpay(payrollStruct [], int[], double[], int);
    void findovertimehours(payrollStruct [], double[], int);
    void findovertimepay(payrollStruct [], double[], double[], int);
    void findgrosspay(double[], double[], double[], int);
    int writeReport(payrollStruct [], int);
    int main()
    {
        int i, code, ret;        // counter
        payrollStruct employees[SZ];  // array of golfers and data
        int numemp;             // total number of golfers
        int regularpay, overtimepay,grosspay;
        tellUser();              // tell user what program does
        numemp= readInput(employees);
        cout << "There were " << numemp << " golfers\n\n";
        if (numemp < 1)
        {
           cout << "Program ending\n\n";
           code = 1;
        }
        else
        {
           // calculate total and average for each golfer
           cout << "calculating average and totals\n";
           // ret= calcAvg(golfers, numgolf);
           // sort golfers
           cout << "Sorting the golfers in order with the winner first\n";
    
           bubbleSort(employees, numemp);
           code = writeReport(employees , numemp); 
        }
        return code;
    }
    /* ***************************************************************
    * function tellUser
    * it tells the user what the program does
    * it prints output to the screen
    * input: none output: tells user on screen what program does
    * returns: none
    ****************************************************** */
    void tellUser()
    {
        cout << "\nThis program reads a file called employees.txt,\n";
        cout << "and it calculates the regular, overtime and gross pay for each golfer.\n";
        cout << "employees are sorted into order with employees last name.\n";
        cout << "output is written to the screen. and to an output file\n";
        cout << "It uses an array of structures to store the data\n";
    }
    /* *********************************************************
    * readInput
    * This function reads golfer data from a file "women.txt"
    * It stores the first and last names of golfers and 4 rounds
    * of golf scores for each golfer in an array of structures
    * input: first and last names, 4 golf scores each person
    * passes back: array of golfer data in structure
    * returns: number of golfers
    *************************************************************** */
    int readInput(payrollStruct emp[])
    {
       ifstream inputFile; // input filename in program
       int numEmp; // number employees
       int i;// counter
       // open file and read input from file golfers.txt
       inputFile.open("employees2.txt");
       if (inputFile.fail()) 
       {
          cout << "Error opening file employees2.txt\n\n";
          cout << "end of program\n\n";
          return 0;
       }
       else
       {
          i = 0; // golfer number for array  
          while ( ( i < SZ) && (inputFile >> emp[i].hoursworked))
          { // there is a line of data to read and array has room
             inputFile >> emp[i].hourlyrate;
             inputFile >> emp[i].empID;
             inputFile >> emp[i].firstname;
             inputFile >> emp[i].lastname; 
             i++; // ready for the next golfer
          } // end while
       numEmp = i; // number golfers
       inputFile.close(); // close the file after reading it
       cout << "input file closed\n\n";
       return numEmp; // return number golfers read in file
       } // end if else
    } // end function readInput
    /* ************************************
    * Function swap
    * this function swaps to golfStructs
    * input parameters: two golf structs
    * output parameters: now swapped with each other
    * ************************** */
    void swap(payrollStruct &empa, payrollStruct &empb)
    {
        payrollStruct temp; // place to store one golfer data
        temp = empb;
        empb = empa;
        empa = temp;
    }
    /* *********************************************************
    * bubble sort with flag
    * this function sorts golfers into order by total score
    * the winner is first with the lowest score, alphabetical
    * order when scores match
    * input parameters: array of golfStruct and number of golfers
    * in that array
    * ouput: those array items are now sorted
    *************************************************************** */
    void bubbleSort(payrollStruct emp[], int numE)
    {
        bool swapmade = false; // when true a swap was made in this pass
        int i, lastpos; // last position to look for correct order
        // sort the golfers from winner to loser
        cout << "sorting employees with their last name\n";
        lastpos = numE;
        do 
        {
          lastpos--;
          swapmade = false;
          for ( i = 0; i < lastpos; i++)
          {
              if ( emp[i].lastname > emp[i+1].lastname) // they are in the wrong order
              { // swap all items here
                  swap(emp[i], emp[i+1]);
                  swapmade = true;
              }
          } // end of for loop   
        } while(swapmade); // end of do loop
    }
    void findregularhours(payrollStruct emp[], int regularhours[], int n)
    {
       for(int i=0; i<n; i++)
       { 
           if(emp[i].hoursworked > 40)     //if the hours is > 40 it will make it 40
                regularhours[i]=40;  //regular hour = 40
           else  
                regularhours[i]=emp[i].hoursworked; 
       }  //end for loop  
    }  //regularhours()
    
    /* regular()
     * calculates employees regular pay
     */
    void findregularpay(payrollStruct emp[], int regularhours[], double regularpay [], int n)
    {
       for(int i=0; i<n; i++)
       {
          regularpay[i] = regularhours[i]*emp[i].hourlyrate;
       }  //end for loop
    }   //regularpay
    /* overtime()
     * finds if th hours are > 40
     */
    void findovertimehours(payrollStruct emp[], double overtimehours[], int n)
    {
       for(int i=0; i<n; i++)
       {
           if(emp[i].hoursworked>40) 
                overtimehours[i]=emp[i].hoursworked-40;  //calculates and finds how many hours are overtime
           else 
                overtimehours[i]=0;  //if there is no overtime
       }  //end for loop
    } // findsovertimehours
    /*findovertimepay()
     * calculates employees overtime pay
     */
    void findovertimepay(payrollStruct emp[], double overtimehours[], double overtimepay[], int n)
    {
        for(int i=0; i<n; i++)
        {
             overtimepay[i]=overtimehours[i]*emp[i].hourlyrate*1.5;   // calculating overtime hours
        } //end for loop
    } // findovertimepay
    
    /* grossPay()
     * calculates employees regular + overtime pay
     */
    void findgrosspay(double regularpay[], double overtimepay[], double grosspay[], int n)
    {
       for(int i=0; i<n; i++)
       {
           grosspay[i]=regularpay[i]+overtimepay[i];  // calculate gross pay
       }  // end for loop
    } //findgrosspay
    
    
    
    
    /* **************************************************************************
    * output report
    * this function writes data to screen and file
    * input parameters: array of golfStructs and number golfers
    * ouput written to screen and file womengolfreport.txt
    * ************************************************************************* */
    int writeReport(payrollStruct emp[],int numE)
    {
        int i; // counter
        
        ofstream outputFile; // output file
        // open report file and write output data ********************
        cout << "Report being written to file payrollreport.txt\n";
        outputFile.open("payrollreport.txt"); // output file
        if (outputFile.fail()) 
        {
            cout << "output file did NOT open\n";
            cout << "output will only be sent to the screen\n";
            cout <<"First          Last       Employee     Hours        Rate      Regular    Overtime    Gross\n";  //table of employees payroll data sheet to the screen
            cout <<"Name           Name        Number      Worked      of Pay       Pay        Pay        Pay\n";
            cout <<"===========================================================================================\n";
    
            for ( i=0; i < numE; i++)  
            {
               // emp[i].place = (i + 1);
                cout << emp[i].firstname << " ";
                cout << emp[i].lastname << " ";
                cout << emp[i].empID << " ";
    	    cout << emp[i].hoursworked << " " << emp[i].hourlyrate<< " ";
    	   // cout << emp[i].regularpay[i] << " ";// << glf[i].rounnd[3] << " ";
     	   // cout << emp[i].totalScore << " ";
           }
        } // end if file did not open
        else 
        {
             cout <<"First          Last       Employee     Hours        Rate      Regular    Overtime    Gross\n";  //table of employees payroll data sheet to the screen
             cout <<"Name           Name        Number      Worked      of Pay       Pay        Pay        Pay\n";
             cout <<"===========================================================================================\n";
             outputFile <<"First          Last        Employee     Hours       Rate      Regular    Overtime    Gross\n";//table of employees payroll data sheet to txt file
             outputFile <<"Name           Name         Number      Worked     of Pay      Pay        Pay        Pay\n";
             outputFile <<"=========================================================================================\n";
    
            // loop to print report of golfers ********************
            for ( i=0; i < numE; i++)
            {
                //glf[i].place = (i + 1);
    	     outputFile << setw(12);
    	     outputFile << emp[i].lastname << " ";
    	     outputFile << emp[i].firstname << " ";
    	     outputFile << emp[i].empID << " " << emp[i].hoursworked<< " ";
    	     outputFile << emp[i].hourlyrate << " ";// << regularpay[i] << " ";
                // outputFile << overtimepay[i] << " " << grosspay[i] << " ";
    
                 cout << setw(13) << fixed << left << emp[i].lastname << " " <<setw(12) << emp[i].firstname << " ";
                 cout << setw(11) << emp[i].empID << " " << setw(11) << fixed << setprecision(2) << emp[i].hoursworked<< " ";
                 cout << setw(8) << fixed << setprecision(2) << emp[i].hourlyrate << "\n";// << regularpay[i] << " ";
                 //cout << overtimepay[i] << " " << grosspay[i] << " ";
    	}
            cout <<"============================================================================================\n";
            cout <<"\t\t\tTotal Gross Pay\t\t\t\t\t             " << fixed << setprecision(2) << " CAL GROSS PAY ONLY" << " \n";
            outputFile <<"============================================================================================\n";
            outputFile <<"\t\t\tTotal Gross Pay\t\t\t\t\t             " << fixed << setprecision(2) << " CAL GROSS PAY ONLY" << " \n";
    	outputFile.close();
           cout << "Output file closed\n\n";
        } // end else output file open
        return 0;
    } // end of writeReport *************************************
    txt file
    Code:
    40.0   10.00 A1234 Jane Adams
    50.0   10.00 L8765 Mary Lincoln
    25.5   10.85 W7654 Martha Washington
    52.0   15.75 A9876 John Adams
    45.0   25.00 W1235 George Washington
    40.25  55.00 L9087 Abraham Lincoln
    30.0    9.75 T9876 William Tell
    42.5   12.50 M7654 Missy Muffett
    30.0   10.00 P8765 Peter Piper
    45.0   15.00 T8765 Zachary Taylor
    50.75  50.00 F5432 Millard Fillmore
    40.0   45.50 P3452 Franklin Pierce
    and this what i get
    Code:
    First          Last       Employee     Hours        Rate      Regular    Overtime    Gross
    Name           Name        Number      Worked      of Pay       Pay        Pay        Pay
    ===========================================================================================
    Adams         Jane         A1234       40.00       10.00
    Adams         John         A9876       52.00       15.75
    Buchanan      James        B7612       23.00       48.55
    Cleveland     Grover       C9856       38.50       25.00
    Fillmore      Millard      F5432       50.75       50.00
    Grant         Ulysses      G5612       60.50       35.00
    Harrison      Benjamin     H5431       30.50       28.50
    Hayes         Rutherford   H6542       45.50       35.50
    Lincoln       Mary         L8765       50.00       10.00
    Lincoln       Abraham      L9087       40.25       55.00
    Muffett       Missy        M7654       42.50       12.50
    Pierce        Franklin     P3452       40.00       45.50
    Piper         Peter        P8765       30.00       10.00
    Roosevelt     Theodore     R1234       56.50       45.25
    Roosevelt     Elenor       R2345       25.00       48.75
    Taylor        Zachary      T8765       45.00       15.00
    Tell          William      T9876       30.00       9.75
    VanBuren      Martin       V4532       42.00       40.75
    Washington    Martha       W7654       25.50       10.85
    Washington    George       W1235       45.00       25.00
    ============================================================================================
                            Total Gross Pay                                               CAL GROSS PAY ONLY

  11. #11
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    Re: need help my (employee payroll program using structures)does not show all data

    There are various ways of approaching this. Possibly the easiest in this case is to add fields to payrollstruct for regularhours etc and to uncomment out regularpay etc. Have the functions findregularhours, findregularpay etc operate directly on the emp parameter so you don't need the regularhours[], regularpay[] arguments etc for the functions. Once the data has been read, call these functions in main() then in writereport() just access the appropriate fields in emp[].
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  12. #12
    Join Date
    Nov 2013
    Posts
    49

    Re: need help my (employee payroll program using structures)does not show all data

    can you show regularpay as an example

  13. #13
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    Re: need help my (employee payroll program using structures)does not show all data

    Code:
    void findregularpay(payrollStruct emp[], /*int regularhours[], double regularpay [],*/ int n)
    {
    	for (int i = 0; i < n; i++) {
    		emp[i].regularpay = emp[i].regularhours * emp[i].hourlyrate;
    	}  //end for loop
    }   //regularpay
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  14. #14
    Join Date
    Nov 2013
    Posts
    49

    Re: need help my (employee payroll program using structures)does not show all data

    so.. correct me if im wrong i followed ur example
    void findregularhours(payrollStruct emp[], //int regularhours[]//, int n)
    {
    for(int i=0; i<n; i++)
    {
    if(emp[i].hoursworked > 40) //if the hours is > 40 it will make it 40
    emp[i].regularhours[i]=40; //regular hour = 40
    else
    emp[i].regularhours[i] = emp[i].hoursworked;
    } //end for loop
    } //regularhours

    ALSO CAN YOU SHOW EXAMPLE OF WHAT YOU MEANT BY:
    - add fields to payrollstruct for regularhours etc and to uncomment out regularpay etc.
    - Once the data has been read, call these functions in main() then in writereport() just access the appropriate fields in emp[].

  15. #15
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    Re: need help my (employee payroll program using structures)does not show all data

    ALSO CAN YOU SHOW EXAMPLE OF WHAT YOU MEANT BY:
    Yes I can, but no I'm not as you should be able to do this yourself as its trivial. What do you think I mean by 'uncomment' and 'add fields to payroll struct for regularhours'?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Page 1 of 4 1234 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center