Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C help

Name: D: 2008-05-07 2:35

I can't get this fucking code to read from a text file (payroll.txt) I have to include with the program. Maybe I'm a dumbass and not putting it in the right place (I put it in the root file where the code goes, but it's not working so...dunno). Anyway, pals, proofread my shitty code if you would be so kind.

/*This program prints a payroll register. It collects data from payroll.txt, an external file
that is put in the folder along with the program.*/

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int test;/*Used simply to stop the program from exiting*/
    FILE *payPtr;
    payPtr = fopen("payroll.txt", "r");
    int i = 1;
    int j = 1;
    double pay, fica, medicare, tax, dues, net, hoursOver;
    double dept200Pay, dept200Ins, dept200Fica, dept200Medicare, dept200Tax, dept200Dues, dept200Net;
    double dept300Pay, dept300Ins, dept300Fica, dept300Medicare, dept300Tax, dept300Dues, dept300Net;
   
    typedef struct {
       int department;
       char name[10];
       double rate;
       double hours;
       double insurance;
       double ytd;
       int code;
       } record; /*Ends structure department*/
       record employee;
   
    printf("%-10s\n%-10s\n", "Weekly Payroll Register", "by: Brad Widger");
    printf("%-6s%-2s%-30s%-3s%-5s", "Employee", "Gross", "Federal.", "Union", "Net");
    printf("Dept.%-4s%-7s%-4s%-3s%-4s%-5s%-6s%-6s", "Name", "Pay", "Insurance", "FICA", "MEDICARE", "Tax",
    "Dues", "Pay");
    printf("------------------------------------------------------------");
   
    while (!feof(payPtr)) {
    fscan(payPtr, "%d%s%lf%lf%lf%lf", &employee.department, &employee.name, &employee.rate,
    &employee.hours, &employee.insurance, &employee.ytd);
     /*end while*/
                    
                    
        if (employee.hours > 40) {
           pay = employee.rate * employee.hours;
           hoursOver = employee.rate - 40;
           pay = pay - (hoursOver * employee.rate) + (hoursOver * (employee.rate * 1.5));
              } /*end if*/
              else {
                   pay = employee.rate * employee.hours;
                   } /*end else*/
       
        if (employee.ytd > 65000.00) {
           fica = .05 * pay;
           medicare = .02 * pay;
           } /*end if*/
           else {
                fica = .07 * pay;
                medicare = .03 * pay;
                } /*end else*/
       
        tax = pay * .25;
       
        if (employee.code = 1) {
           dues = 35.00;
           } /*end if*/
           else {
                dues = 0.00;
                } /*end else*/
               
        net = pay - employee.insurance - fica - medicare - tax - dues;
       
        if (employee.department = 200) {
           printf("%d%s%lf%lf%lf%lf%lf%lf%lf", &employee.department, employee.name, &pay,
           &employee.insurance, &fica, &medicare, &tax, &dues, &net);
           dept200Pay =+ pay;
           dept200Ins =+ employee.insurance;
           dept200Fica =+ fica;
           dept200Medicare =+ medicare;
           dept200Tax =+ tax;
           dept200Dues =+ dues;
           dept200Net =+ net;
           } /*end if*/

        if (employee.department = 300) {
           printf("%d%s%lf%lf%lf%lf%lf%lf%lf", &employee.department, employee.name, &pay,
           &employee.insurance, &fica, &medicare, &tax, &dues, &net);
           dept300Pay =+ pay;
           dept300Ins =+ employee.insurance;
           dept300Fica =+ fica;
           dept300Medicare =+ medicare;
           dept300Tax =+ tax;
           dept300Dues =+ dues;
           dept300Net =+ net;
           } /*end if*/
          
 
  } /*end while*/
 
  /*fclose(payPtr);*/
  scanf("%d", &test); /*Stops program from ending*/

return 0;
} /*Ends main*/

Name: D: 2008-05-07 3:30

*facepalm* Thanks, I'm an idiot. How I let that go by unscene for so long is beyond me. When I throw that into a compiler, all it does is run 0's forever. Any idea what else could be wrong with it? Here's the data in payroll.txt if it helps.

200 JAdams 25.900000 40.000000 50.060000 500000.000000 1
200 SJones 20.950000 48.500000 4.000000 132000.000000 2
200 JSmith 11.900000 3.500000 10.020000 12000.000000 2
300 FBayes 13.450000 59.800000 9.900000 64419.500000 2
300 HCalvin 7.900000 36.700000 10.000000 0.000000 1

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List