Thread: Help with a payroll program

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    5

    Help with a payroll program

    I'm trying to make a payroll program, however I don't really know where to go from the point that i am at. In a .dat file created in notepad, i have entered the employee number, their pay rate and the hours that they have worked, seperating each of them by a space and giving each employee their own line. I want it to calculate the o/t hours and gross pay and print everything out with headings and a total amount of hours and such at the bottom, without prompting the user.

    Thanks

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Go read the rules, we wont do your homework. Show us some code and effort and then post.

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    46
    Have you written the code to read a single record from the file? Once you can do that, it's a simple matter to read multiple records with a loop. Formatting the output is equally simple when you have the data.

  4. #4
    Registered User
    Join Date
    Feb 2004
    Posts
    5
    i guess that is what i'm trying to say that i don't understand

  5. #5
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    have you tried doing anything? post whatever you have done so far.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  6. #6
    Registered User
    Join Date
    Feb 2004
    Posts
    5
    sorry, but here is the code i have
    Code:
    using namespace std;
    
    int main()
    {
       int    employee;
       double overTimeThreshold,
              rate,
              hours;
       
       cout << "Employee No.\t";
       cout << "Pay Rate\t";
       cout << "Hours\t";
       cout << "O/T Hours\t";
       cout << "Gross Pay\t";
       
       ifstream project2;
       project2.open("project2.dat");
    
    int overtime;
    int empNum;
    project2>>overtime;
    project2>>empNum;
    while(project2)
    {
    
    project2>>empNum;
    project2>>payRate;
    project2>>hoursWorked;
    }
       return 0;
    }
    Last edited by xc-racer; 02-22-2004 at 10:43 PM.

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Please edit your post and place a / after the [ and before CODE at the end of your code to get the effect desired for posting code on this board

    Then take a piece of paper and a pencil and write down all the steps you need to do BEFORE you try to write code. It may be as simple as this:

    declare ifstream
    open ifstream associated with file to read

    declare variables for:
    employee number
    pay rate
    hours worked
    overtime hours
    overtime pay rate
    total pay


    while there is data in the file do the following:
    read in employee number
    read in pay rate
    read in hours worked
    calculate overtime hours
    determine total pay = pay for std hours + pay for overtime hours
    print desired data to screen
    repeat process for next employee


    Now try to elaborate on each of those tasks writing pseudocode
    Then change the pseudocode into code.
    Do this for every project you do and you'll write better code, faster.

    Good luck.

  8. #8
    Registered User
    Join Date
    Feb 2004
    Posts
    5
    I really appreciate your help and here is the code that I have now
    Code:
    #include <fstream>   //Allows you to read and write data to and from files.
    #include <iostream>  //Needed for cin, cout.
    #include <stdlib.h>  //Needed for system().
    #include <iomanip>   //Needed to control printing.
    
    using namespace std;
    
    int main()
    {
       int empNum;
       double overTime,
              overTimePay,
              grossPay,
              rate,
              hoursWorked,
              overTimeHours,
              overTimeThreshold = 40.00;
       
       cout << "Employee No.\t";
       cout << "Pay Rate\t";
       cout << "Hours\t";
       cout << "O/T Hours\t";
       cout << "Gross Pay\t";
       
       ifstream project2;
       project2.open("project2.dat");
    
       project2>>overTime;
       project2>>empNum;
    
       while(project2){
          project2>>empNum;
          project2>>rate;
          project2>>hoursWorked;
            if(hoursWorked <= overTimeThreshold){
               overTimeHours = 0.00;
               grossPay = (hoursWorked * rate);
            }
            else{
               overTimeHours = hoursWorked - overTimeThreshold;
               grossPay = (overTimeThreshold* rate)+ (1.5(hoursWorked - overTimeThreshold));
            }
          project2>>empNum;
       }
       
       return 0;
    }
    the compiler is still picking up an error in the last else statement and i can't find it, so it won't compile the .exe file for me.

  9. #9
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    if i took it right u want to multiply 1.5 by hoursWorked - overTimeThreshold, so i added the *....

    Code:
    grossPay = (overTimeThreshold* rate)+ (1.5*(hoursWorked - overTimeThreshold));
    BTW, compiled like that in Dev C++.

  10. #10
    Registered User
    Join Date
    Feb 2004
    Posts
    5
    ok thanks, i changed the 1.5 to "overTimeBonus" and I found the other error to be a capitalization mistake. The problem is now I don't know how to output the data that i am reading from the text file.

    the text file looks lie
    40.0
    12345 6.79 40.00
    20034 10.00 45.00
    23328 8.75 62.50

  11. #11
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    try a board search on the infile and outfile functions, i think they will help you out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM