我創建一個工資計算程序,這裏是我的代碼變量或字段宣告無效」和其他錯誤
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define REPORTHEADING1 " Employee Pay Hours Gross Tax Net\n"
#define REPORTHEADING2 " Name Rate Worked Pay Due Pay\n"
#define REPORTHEADING3 " =============== ==== ====== ===== ==== ====\n"
#define REPORTHEADING4 " ==== ====== ===== ==== ====\n"
#define REPORTLINEFORMAT1 " %-20s%6.2f%11.2f%9.2f%9.2f%10.2f\n"
#define REPORTLINEFORMAT2 " Totals %6.2f%11.2f%9.2f%9.2f%10.2f\n"
#define REPORTLINEFORMAT3 " Averages %6.2f%11.2f%9.2f%9.2f%10.2f\n"
#define COUNTLINEFORMAT " Number of employees: %-10i\n\n"
#define MAXREGHOURS 40
#define OVERTIMERATE 1.5
enter code here
void PrintReportHeadings(FILE *reportFile); //printReportHeadings prototype
void InitializeAccumulators(float *totRegHour,float *totOvtHours,float *totPayrate,
float *totGross,float *totdeferred,float *totFedtax,
float *totStatetax,float *totSSItax,float *totNet,int *empCount); //InitializeAccumulators prototype
void InputEmployeeData(char *firstName,char *lastName,
float *hours,float *payrate,float *deferred); //InputEmployeeData prototype
void CalculateGross(float hours,float payrate,float *regHours,float *ovtHours,
float *gross); //CalculateGross prototype
extern void CalculateTaxes(float gross,float deferred,float * fedtax,
float * statetax,float * ssitax); //CalculateTaxes prototype (external)
float CalculateNetPay(float gross,float fedtax,float statetax,float ssitax,
float deferred);
void AddDetailToAccumulators(float regHours,float ovtHours,float payrate,
float gross,float deferred,float fedtax,float statetax,
float ssitax,float net,float *totRegHours,float *totOvtHours,
float *totPayrate,float *totGross,float *totdeferred,
float *totFedtax,float *totStatetax,float *totSSItax,
float *totNet);
void PrintSummaryReport(FILE *reportFile,char fullName,float regHours,float ovtHours,
float payrate,float gross,float deferred,float fedtax,
float statetax,float ssitax,float net);
int main(void)
{
float ft,st,ssit;
char firstName[10+1];
char lastName[15+1];
char fullName[25+1];
float regHours, ovtHours, hours, payrate, deferred, gross, netpay;
float totRegHours, totOvtHours, totPayrate, totGross,totdeferred,
totFedtax, totStatetax, totSSItax, totNet;
int empcount;
char answer;
FILE * reportFile;
reportFile = fopen("./report.txt","wt");
if(reportFile = NULL)
{
printf(" Report open request failed...\n");
while(getchar() != '\n');
exit(-90);// reqs <stdlib.h>
}
PrintReportHeadings(reportFile);
InitializeAccumulators(&totRegHours,&totOvtHours,&totPayrate,&totGross,
&totdeferred,&totFedtax,&totStatetax,&totSSItax,&totNet,
&empcount);//set all accumulators to 0
do
{
InputEmployeeData(firstName,lastName,&hours,&payrate,&deferred);
CalculateGross(hours, payrate, ®Hours, &ovtHours, &gross);
CalculateTaxes(gross,deferred,&ft,&st,&ssit);
netpay = CalculateNetPay(gross,ft,st,ssit,deferred);
strcpy(fullName,lastName);
strcat(fullName,", ");
strcat(fullName,firstName);
AddDetailToAccumulators(regHours,ovtHours,payrate,gross,deferred,ft,st,
ssit,netpay,&totRegHours,&totOvtHours,&totPayrate,&totGross,
&totdeferred,&totFedtax,&totStatetax,&totSSItax,&totNet);
void PrintSummaryReport(reportFile,fullName,regHours,ovtHours,payrate,gross,deferred,
ft,st,ssit,netpay)
empcount++;
printf(COUNTLINEFORMAT,empcount);
printf(" do you have anymore? (Y/N): ");
while(getchar() != '\n');
answer = getchar();
printf("\n");
}
while(answer != 'N' && answer != 'n');
while (getchar()!= '\n');
getchar();
return 0;
}
void PrintReportHeadings(FILE *reportFile)
{
reportFile = fopen("./report.txt","wt");
fprintf(reportFile,REPORTHEADING1);
fprintf(reportFile,REPORTHEADING2);
fprintf(reportFile,REPORTHEADING3);
}
void InitializeAccumulators(float *totRegHour,float *totOvtHours,float *totPayrate,
float *totGross,float *totdeferred,float *totFedtax,
float *totStatetax,float *totSSItax,float *totNet,int *empCount)
{
totRegHour, totOvtHours, totPayrate, totGross,totdeferred,
totFedtax, totStatetax, totSSItax, totNet, empCount = 0;
}
void InputEmployeeData(char *firstName,char *lastName,float *hours,
float *payrate,float *deferred)
{
printf(" Enter employee first name : ");
scanf("%s",firstName);
printf(" Enter employee last name : ");
scanf("%s",lastName);
printf(" Enter %s's hours worked : ",firstName);
scanf("%f",hours);
printf(" Enter %s's pay rate : ",firstName);
scanf("%f",payrate);
printf(" Enter %s's amount deferred : ",firstName);
scanf("%f",deferred);
}
void CalculateGross(float hours,float payrate,float *regHours,float *ovtHours,float *gross)
{
float overtimeHours(float hours);
if(hours <= MAXREGHOURS)
{
*regHours = hours;
*gross = hours * payrate;
}
else
{
*regHours = MAXREGHOURS;
*ovtHours = overtimeHours(hours);
*gross = payrate * MAXREGHOURS + OVERTIMERATE * payrate * (hours - MAXREGHOURS);
}
}
float overtimeHours(float hours)
{
return hours - MAXREGHOURS;
}
float CalculateNetPay(float gross,float fedtax,float statetax,float ssitax,
float deferred)
{
return gross - (fedtax + statetax + ssitax + deferred);
}
void AddDetailtoAccumulators(float regHours,float ovtHours,float payrate,
float gross,float deferred,float fedtax,float statetax,
float ssitax,float netpay,float *totRegHours,float *totOvtHours,
float *totPayrate,float *totGross,float *totDeferred,
float *totFedtax,float *totStatetax,float *totSSItax,
float *totNet)
{
*totRegHours =+ regHours;
*totOvtHours =+ ovtHours;
*totPayrate =+ payrate;
*totGross =+ gross;
*totDeferred =+ deferred;
*totFedtax =+ fedtax;
*totStatetax =+ statetax;
*totSSItax =+ ssitax;
*totNet =+ netpay;
}
void PrintSummaryReport(FILE *reportFile,char fullName,float regHours,float ovtHours,
float payrate,float gross,float deferred,float fedtax,
float statetax,float ssitax,float netpay)
{
reportFile = fopen("./report.txt","wt");
fprintf(reportFile,REPORTLINEFORMAT1,fullName,payrate,regHours,gross,fedtax,
ssitax,netpay);
fprintf(reportFile,REPORTLINEFORMAT2,ovtHours,statetax,deferred);
printf(reportFile,REPORTLINEFORMAT1,fullName,payrate,regHours,gross,fedtax,
ssitax,netpay);
printf(reportFile,REPORTLINEFORMAT2,ovtHours,statetax,deferred);
}
我得到的錯誤是: 變量或字段PrintSummaryReport宣佈無效
然後我也得到: 在功能voidPrintSummaryReport ...... 不能將文件轉換爲const車參數爲int的printf(爲const char * ...) 是以下行
printf(reportFile,REPORTLINEFORMAT1,fullName,payrate,regHours,gross,fedtax,
ssitax,netpay);
printf(reportFile,REPORTLINEFORMAT2,ovtHours,statetax,deferred);
你的函數調用是不正確 – mangusta