我无法解决这个问题,需要显示一个netpay。对于作业,我必须有一个外部功能。我保留这个:
calcTax.cpp:在函数'void calculateTaxes(float,float,float *,float *,float *,float *)'中:
calcTax.cpp:61:56:错误:无法将参数'2'的'float'转换为'float *'为'float calcNet(float,float *,float *,float *,float)'
* totNet = calcNet(毛,* fedtax,* statetax,* ssitax,defr);
我对编码很新,所以任何帮助都会很棒。第一部分是主文件中的外部和第二部分。
#define FEDTAXRATE 0.15
#define STATETAXRATE 0.07
#define SSITAXRATE 0.0775
float calcFedTax(float gross, float defr);
float calcStateTax(float fedtax);
float calcSSITax(float gross,float defr);
float calcNet(float gross, float *fedtax, float *statetax, float *ssitax,float defr);
void calculateTaxes(float gross,float defr,float *fedtax,float *statetax,float *ssitax,float$
{
*fedtax = calcFedTax(gross,defr);
*statetax = calcStateTax(*fedtax);
*ssitax = calcSSITax(gross,defr);
*totNet = calcNet(gross,*fedtax,*statetax,*ssitax,defr);
}
float calcFedTax(float gross,float defr)
{
return(gross - defr) * FEDTAXRATE;
}
float calcStateTax(float fedtax)
{
return fedtax * STATETAXRATE;
}
float calcSSITax(float gross,float defr)
{
return(gross-defr) * SSITAXRATE;
}
float calcNet(float gross, float *fedtax, float *statetax, float *ssitax,float defr)
{
return(gross - *fedtax - *statetax - *ssitax - defr);
}
#include <stdio.h>
#include <stdlib.h>
#define FEDTAXRATE .15
#define STATETAXRATE .07
#define SSITAXRATE .0775
#define ADDR(var) &(var)
void PrintReportHeading(FILE *reportfile);
void getEmployeeInput(char firstname[],char lastname[],float * Reg,float * payrate,float *defr);
float calculateGross(float Reg,float payrate);
float calculateNet(float gross,float defr,float ft,float st,float ssit);
extern void calculateTaxes(float gross,float defr,float *fedtax,float *statetax,float *ssitax);
void addDetailToAccumulators(float payrate,float Ovt,float Reg,float gross,float ft,float st,float ssit,
float defr,float Net,float *totRate,float *totOvt,float *totReg,float *totGross,float *totFed,
float *totState,float *totSSI,float *totDefr,float *totNet);
void printSummaryReport(char lastname[], char firstname[],FILE *reportfile, float payrate, float Reg, float gross,
float ft, float ssit, float Net, float st, float defr, float Ovt);
int main(void)
{
char lastname[15+1];
char firstname[10+1];
float hours=0, payrate=0, defr=0, gross=0, ft=0, st=0, ssit=0, Ovt=0, Reg=0, Net=0, totReg=0,
totDefr=0, totOvt=0, totNet=0, totState=0, totRate=0, totGross=0, totFed=0, totSSI;
FILE * reportfile;
reportfile = fopen("./report.lst","wt");
if (reportfile == NULL)
{
printf(" Report file open failed ...\n");
while (getchar() != '\n');
exit(-100);
}
PrintReportHeading(reportfile);
getEmployeeInput(lastname,firstname,ADDR(Reg),ADDR(payrate),ADDR(defr)); //3.3
gross = calculateGross(Reg,payrate); //call 3.4
Net = calculateNet(gross,defr,ft,st,ssit);
calculateTaxes(gross,defr,ADDR(ft),ADDR(st),ADDR(ssit));
addDetailToAccumulators(payrate, Ovt, Reg, gross, ft, st, ssit, defr, Net, ADDR(totRate), ADDR(totOvt), ADDR(totReg), ADDR(totFed), ADDR(totFed),ADDR(totState),
ADDR(totSSI),ADDR(totDefr),ADDR(totNet));
printSummaryReport(firstname,lastname,reportfile,payrate,Reg,gross,ft,ssit,Net,st,defr,Ovt);
while (getchar() != '\n');
return 0;
}
void PrintReportHeading(FILE *reportfile)
{
fprintf(reportfile," Employee Pay RegHrs/ Gross Fedtax StateTax Net\n");
fprintf(reportfile," Name Rate OvtHrs Pay SSItax Defr Pay\n");
fprintf(reportfile," ======== ====== ====== ====== ====== ======== ======\n");
}
void getEmployeeInput(char *firstname,char *lastname,float *Reg,float *payrate,float *defr)
{
printf("Enter the employee's first name ===> \n");
scanf("%s", firstname);
printf("Enter the employee's last name ===> \n");
scanf("%s", lastname);
printf("Enter the hours worked this pay period ===> \n");
scanf("%f", Reg);
printf("Enter the hourly payrate ===> \n");
scanf("%f", payrate);
printf("Enter the deferred earnings ===> \n");
scanf("%f", defr);
}
float calculateGross(float Reg,float payrate)
{
if (Reg <= 40)
return Reg * payrate;
else
return 40 * payrate + 1.5*payrate*(Reg-40);
}
void addDetailToAccumulators(float payrate,float Ovt,float Reg,float Gross,float ft,float st,float ssit,
float defr,float Net,float *totRate,float *totOvt,float *totReg,float *totGross,float *totFed,
float *totState,float *totSSI,float *totDefr,float *totNet)
{
*totRate = *totRate + payrate;
*totOvt = *totOvt + Ovt;
*totReg = *totReg + Reg;
*totGross = *totGross + Gross;
*totFed = *totFed + ft;
*totState = *totState + st;
*totSSI = *totSSI + ssit;
*totDefr = *totDefr + defr;
*totNet = *totNet + Net;
}
void printSummaryReport(char firstname[], char lastname[], FILE *reportfile, float payrate, float Reg, float gross,
float ft, float st, float Ovt, float ssit, float defr, float Net)
{
fprintf(reportfile,"%10s,%7s%8.2f%12.2f%12.2f%12.2f%12.2f%12.2f \n",firstname,lastname,payrate,Reg,gross,ft,st,Net);
fprintf(reportfile," %8.2f%17.2f \n",ssit,defr);
}
答案 0 :(得分:2)
错误不言自明。您正在传递float
值,而calcNet()
函数需要float*
指针
您的fedtax
,statetax
和ssitax
参数已经是float*
指针,因此请按原样传递它们,在传递时不要取消引用它们他们到calcNet()
。 IOW,改变这个:
*totNet = calcNet(gross,*fedtax,*statetax,*ssitax,defr);
到此:
*totNet = calcNet(gross,fedtax,statetax,ssitax,defr);