gpt4 book ai didi

c - 简单的段错误,我似乎找不到问题所在

转载 作者:行者123 更新时间:2023-11-30 20:37:53 26 4
gpt4 key购买 nike

可能有一个简单的解决方案,但作为菜鸟,我似乎找不到问题。当我第一次运行该程序时,一切都很好,但在 scan("%f",hrs) 之后我收到“段错误(核心已转储)”。任何帮助将不胜感激,谢谢。如果您也想查看完整代码 you can find it here.

这是我收到的警告:格式“%f”需要“float *”类型的参数,但参数 2 的类型为“double

float grossModule(float *hours, float payrate, float *overtimeHours);
void CalculateTaxes(float *gross, float *defr, float *fedtax, float *statetax, float *ssitax);
float calcFedtax(float gross, float defr);
float calcStatetax(float fedtax);
float calcSSItax(float gross, float defr);
float netModule(float *gross, float *ft, float *st, float *ssit);

int main(void)
{
float dfr,ft,st,ssit,gross,hrs,pay,net,ovrtHrs;
int counter = 0;
float netTotal, payTotal, hoursTotal, overtimeTotal, grossTotal, fedTotal, stateTotal, ssiTotal, dfrTotal;
float grossAvg, netAvg, payAvg, hoursAvg, overtimeAvg, fedAvg, stateAvg, ssiAvg, dfrAvg;
char fName[11], lName[21], ask[4];
FILE * myreport;
myreport = fopen("reports.txt","wt");

fprintf(myreport, header1);
fprintf(myreport, header2);
fprintf(myreport, header3);

netTotal = payTotal = hoursTotal = overtimeTotal = grossTotal = fedTotal = stateTotal = ssiTotal = dfrTotal = 0;
dfr = ft = st = ssit = gross = hrs = pay = net = ovrtHrs = 0;

do
{
counter++;
printf("Please enter your FIRST name: ");
scanf("%s",fName);
printf("Please enter your LAST name: ");
scanf("%s",lName);
printf("Enter your payrate: \n");
scanf("%f",pay);
printf("Please enter your total hours: ");
scanf("%f",hrs);
printf("Please enter the amount of deferred earnings: ");
scanf("%f",dfr);

最佳答案

改变

 scanf("%f",pay);
printf("Please enter your total hours: ");
scanf("%f",hrs);
printf("Please enter the amount of deferred earnings: ");
scanf("%f",dfr);Change

 scanf("%f", &pay);
printf("Please enter your total hours: ");
scanf("%f", &hrs);
printf("Please enter the amount of deferred earnings: ");
scanf("%f", &dfr);

scanf 需要变量的地址,而不是它的内容。

顺便说一句,编译器应该为此发出警告。

关于c - 简单的段错误,我似乎找不到问题所在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31510845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com