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: Anonymous 2008-05-07 7:52

>>18
>Moreover, there is no stdio() function in std C (nor fsay())
NOR say, DUMBASS! HOW ABOUT USING YOUR BRAIN FIRS HUH?
This is a http://www.opengroup.org/onlinepubs/007908799/xsh/puts.html page, where I replaced puts with say, because i fucking love Perl's new say function.

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