Write a Program to perform Weekly Department Salary Report program

timer Asked: Feb 28th, 2014

Question description

Whenever a user inputs anything besides a "single" word, the program crashes. I tried using fgets and sscanf, but then it doesnt prompt the user to input anything at all.. Help~ Below is my code. Another question is, how to align the output in a straight line? Everytime the digit is different, the alignment screws up.

My code

/* A Program to perform Weekly Department Salary Report program*/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int main(void)


FILE *f;

    f = fopen("c:\\class\\pay.txt","w");

    if (f == NULL)


    printf("Error opening file!\n");



char dname[21],ename[100][21],sname[100][21],name[100][21],uantity[5];

char artist[21];

int credit;

int i =0,j,len,bal;

float stotal[100],total[100],finaltot, hwage[100],otime[100],owage[100],gross[100],trwork=0,towork=0,trwage=0,towage=0,totwage=0,percent=0;

char pay;

    char exit ='y';

char output[500] = "";



printf("Mountain Pacific Corporation\n");

printf("Department Salary Program\n\n");

 printf("Please enter the name of the department:  ");





    printf("Enter employee first name#%d:  ",i+1);


    printf("Enter employee second name#%d:  ",i+1);



strcat(ename[i]," ");



    len = strlen(ename[i]);


if (len < 21) 

for (j = 1; j < (21 - len); j++)



*//// The above code still doesn't work.

printf("Enter employee #%d: ",i+1);


//scanf("%[^ \n]s",ename[i]);  

//scanf("%i[^\n]", ename[i]);

    printf("Enter the hourly wage of %s :",ename[i]);


    printf("Enter total number of hours: ");


    printf("\n\nThank you. Process another employee? ");


    i = i + 1;



while (pay == 'y' || pay == 'Y');


    fprintf(f,"\n\nMountain Pacific Corporation");

fprintf(f,"\n\nDepartment Salary Program");

fprintf(f,"\n\nDepartment: %s",&dname);

fprintf(f,"\n\nEmployee                Reg Hrs        Overtime Hrs       Gross\n");


 for (j=0;j<i;j++)



    if (total[j] <= 40)


     stotal[j] = total[j];

     otime[j] = 0;




     stotal[j] = 40;

     otime[j] = total[j]-40;


     owage[j] = hwage[j] * 1.5;

     gross[j]= hwage[j] * stotal[j] + otime[j] * hwage[j]*1.5;

     fprintf(f,"%s  %10.1f ($%.2f)    %4.1f ($%.2f)     $%4.2f\n",ename[j],stotal[j],hwage[j],otime[j],owage[j],gross[j]);    



for (j=0;j<i;j++)


    trwork = trwork + stotal[j];

    trwage = trwage + hwage[j]*stotal[j];

    towork = towork + otime[j];

    towage = towage + owage[j] * otime[j];

    totwage = totwage + gross[j];


percent = (towork / (towork + trwork)) * 100;

fprintf(f,"\nTotal Regular Hours Worked: %.1f",trwork);

fprintf(f,"\nTotal Overtime Hours Worked: %.1f",towork);

fprintf(f,"\nPercentage of Total Hours That Are Overtime: %.1f %",percent);

fprintf(f,"\n\n\nTotal Regular Wages: $%.2f",trwage);

fprintf(f,"\nTotal Overtime Wages: $%.2f",towage);

fprintf(f,"\n\n\nTotal Wages This Period: $%.2f",totwage);



 return 0;


Tutor Answer

(Top Tutor) Studypool Tutor
School: Cornell University
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors