Thread: Payroll- I'm completely stuck

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    1

    Payroll- I'm completely stuck

    The Problem: Payroll – W2 Forms
    Companies have to issue W2 forms for all of their employees for tax purposes. In this program, you will write a program that assists a company in creating W2 forms.

    Many companies have a system where employees clock in and clock out to determine how much time they work each week. Since these records are already automatically stored in files on companies' computers, it only makes sense to use these files to help calculate how much each employee should get paid. (Once this is calculated, then tax information for the W2 form can also be calculated.) In order to determine how much an employee gets paid each week, you need to know the following two pieces of information:

    1) The number of hours they worked in a week
    2) Their hourly pay rate

    If an employee works 40 or less hours a week, then they simply get paid the number of hours they worked times their hourly pay rate. If an employee works more than 40 hours, then they get paid an extra 50% of their regular pay for the hours over 40 they worked. (For example, if an employee's pay rate is $10/hour and the employee works 50 hours, then he/she would get paid $550, because he/she gets $10x40 = 400 normally, plus an extra 1.5x(10 hr)x($10/hr) = $150 for his/her last ten hours of work.

    Following this calculation, you will also have to calculate the amount of money withheld for taxes. Here is the rule that will be used to calculate how much money is withheld for taxes each week:

    1) 10% of regular pay (pay for the first 40 hours) will be withheld for taxes.
    2) 20% of overtime pay (pay for any time beyond 40 hours) will be withheld for taxes.

    For example, if an employee's pay rate is $10/hour and the employee works 50 hours, then he/she would get $70 withheld from their taxes because he/she got $400 (40hrs x $10/hr) regular pay from which $40 is withheld, and he/she got $150 (10hrs x $15/hr) overtime pay from which $30 is withheld.

    You are to write a program that reads in the raw time data from the file "clock2.txt", processes the W2 forms and outputs the final forms to the file "w2.txt". The input file will consist of all employee data for several weeks. Your output file contain W2 "forms" for each employee. You are guaranteed that the file will contain data for no more than 20 employees.
    Format of clock.txt
    The first line of the file will contain a single positive integer, n, in between 1 and 20, inclusive, which represents the number of employees at the company. The next n lines of the file will contain the first name of the current employee, the last name of the current employee and a single positive real number representing his/her hourly pay rate. Each name will contain fewer than 30 characters. Each piece of data on the line will be separated by a space. (Note: No two employees will have the same exact first AND last names. Thus, there can't be two Steve Smith's but there can be a Steve Jones and a Steve Smith.) The next line of the file will contain a single positive integer, k, which represents the total number of sets of data contained in the file. Each set of data represents the data for a single week. The first line of each set of data will contain a single positive integer m, representing the number of employee records for the week. (Note: a single employee record denotes one instance of an employee clocking in and clocking out.) The following m lines will contain one employee record each. Each employee record will have the following format:

    LastName FirstName HrIn MinIn HrOut MinOut

    The first two pieces of information will be strings storing the last name and first name, respectively, of the employee clocking in and out. (Note: You are guaranteed that these names will match EXACTLY one employee initially listed in the file.) The last four values on a line will be integers. The first integer, HrIn, represents the hours (in military time) that the given employee clocked in to work. This value is guaranteed to be in between 0 and 23, inclusive. The second integer, MinIn, represents the minutes (in military time) that the given employee clocked in to work. This value is guaranteed to be in between 0 and 59, inclusive. The last two values, HrOut and MinOut, represent the hours and minutes respectively (in military time), that the given employee clocked out of work. You are guaranteed that this second time occurs later in the day than the first. (Thus, no employee EVER works through midnight.) Thus, the following line:

    Williams Steve 8 0 16 30

    means that employee Steve Williams worked from 8am to 4:30pm, for a total of 8.5 hours.

    Format of w2.txt
    The first line of the output file will contain the following

    Number of employees: n

    where n is the number of employees in the company. The second line will be blank. Following that will be n sets of data, one for each employee in the input file. Each set of data will be separated by two blank lines. The first two lines of each set of data will read:

    W2 Form
    -------

    The third line of each set of data will have the following format:

    Name: First Last

    where First and Last are the first and last names of the current employee, respectively. (The employees should be printed out in the order in which they were originally read in from the input file.)

    The fourth line for each set of data should have the following format:

    Gross Pay: XXX.XX

    where XXX.XX represents the gross pay (in dollars) for the current employee rounded to the nearest cent.

    The fifth line for each set of data should have the following format:
    Taxes Withheld: XXX.XX

    where XXX.XX represents the taxes withheld (in dollars) for the current employee rounded to the nearest cent over the whole pay period specified in the input file.

    The last line of each data set will be of the format:

    Net Pay: XXX.XX

    where XXX.XX represents the net pay for the current employee rounded to the nearest cent over the whole pay period specified in the input file. (The net pay is simply the gross pay minus the taxes withheld.)

    Implementation Requirements
    You must utilize the following struct to store information about a single employee:

    Code:
    struct employee {
      char first[MAX_LEN];
      char last[MAX_LEN];
      double payperhr;
      double gross;
      double taxes;
      double hours_in_week;
    }
    In particular, the first three fields will store the standard information about the employee. The next two fields will be updated at the end of each work week and will store the adjusted gross pay and taxes withheld. Finally, the last component keeps track of the number of hours the employee has worked in the current week. (Thus, this needs to get reset to 0 after finishing reading in each week's information. The reason for this is that the amount of tax withheld can ONLY be determined after reading through a whole week's worth of information – thus, hours_in_week will be updated numerous times while reading in information for a single week. But, gross and taxes will only be updated after a whole week's worth of data has been read in. Also, hours_in_week has to be reset to 0 at the end of each week.)

    Furthermore, your main must contain an array of type struct employee of size 20. (Note: 20 should be stored in a constant that is declared with a #define. Also, define MAX_LEN as a constant equal to 30 and be used for the strings, since each name is guaranteed to be fewer than 30 characters long.)

    Any help would be great!
    Last edited by Salem; 11-27-2007 at 03:55 AM. Reason: Put the code tags just around the code!

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I can't imagine anybody wanting to read that in the format you have posted.

    Todd

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Yeah, code blocks are only good for code, not actual messages.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code tags fixed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    >Any help would be great!
    Asking a question would be great!

    Right now your post is TL;DR.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ok, so this homework that you've got, perhaps you could supply us with a simple question that you feel will get you unstuck - as the rules here is that we don't do your homework. We will happily help you with a few clues, hints and solving some particular little portion of your code, but not write the whole ruddy thing. [It's not us that need the practice - you can't learn to program by letting others do it for you [that's the management course, not the programming course ]]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Sep 2007
    Posts
    16
    lol this kid must be in my class right now im pretty stuck on the same problem mainly having issues figuring out where to start i mean it has to be done with structures but i dont really know how to do a structure with multiple weeks like for example the entire input file goes like this

    2
    John Slacker 5.15
    Jane Worker 10.00
    10
    5
    Worker Jane 9 0 13 45
    Slacker John 10 50 18 10
    Slacker John 7 30 13 30
    Worker Jane 8 30 18 50
    Slacker John 12 20 13 20
    4
    Worker Jane 8 0 18 0
    Worker Jane 8 0 19 0
    Worker Jane 8 0 19 0
    Worker Jane 8 0 20 0
    2
    Slacker John 10 0 15 0
    Worker Jane 8 0 20 0
    2
    Slacker John 10 0 15 0
    Worker Jane 8 0 20 0
    2
    Slacker John 10 0 15 0
    Worker Jane 8 0 20 0
    2
    Slacker John 10 0 15 0
    Worker Jane 8 0 20 0
    2
    Slacker John 10 0 15 0
    Worker Jane 8 0 20 0
    2
    Slacker John 10 0 15 0
    Worker Jane 8 0 20 0
    2
    Slacker John 10 0 15 0
    Worker Jane 8 0 20 0
    2
    Slacker John 10 0 15 0
    Worker Jane 8 0 20 0

    which basically starts with the number of employees there pay and then the following lines are how much they worked... im totally confused on how to get it to read in each line individually to do the computations... any hint with that would be nice! thanks

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    2
    John Slacker 5.15
    Jane Worker 10.00
    10
    5
    What does this red 10 mean?

    Code:
    char buff[BUFSIZ];
    while ( fgets( buff, sizeof buff, fp ) != NULL ) {
      if ( sscanf( buff, "%d", &nRecords ) == 1 ) {
        int i = 0;
        while ( i < nRecords && fgets( buff, sizeof buff, fp ) != NULL ) {
          printf( "%d : %s", i, buff );
          i++;
        }
      }
    }
    Try reading your file with that code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. completely stuck understanding how to use time.h
    By pastitprogram in forum C++ Programming
    Replies: 11
    Last Post: 04-04-2008, 10:11 AM
  2. Complete C noob...and completely stuck lol
    By JST212 in forum C Programming
    Replies: 6
    Last Post: 03-02-2008, 10:54 AM
  3. I'm completely stuck!
    By tek in forum C++ Programming
    Replies: 0
    Last Post: 08-23-2003, 06:43 PM