gpt4 book ai didi

c - 调试断言失败,使用 C 的输入格式无效

转载 作者:行者123 更新时间:2023-11-30 17:12:22 24 4
gpt4 key购买 nike

在我的程序上收到调试断言失败的错误消息,我搜索了类似的问题,但没有看到任何与我的问题相关的问题。如果有人能告诉我我做错了什么,我将不胜感激。错误消息显示表达式:输入格式无效。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 20

struct input
{
char emplyName[5][SIZE];
float emplyHours[5];
float emplyRate[5];
float emplyGross[5];
float emplyBase[5];
float emplyOvrt[5];
float emplyTax[5];
float emplyNet[5];
float emplyTotal[5];
};

void employeeInfo(struct input *emply)
{
int i;

for (i = 0; i < 5; i++){
printf("Enter employee name -1 to end.\n");
scanf_s("%s", &emply->emplyName[i], SIZE);
printf("Enter employee hours.\n");
scanf_s("%.2f", &emply->emplyHours[i]);
printf("Enter Hourly rate.\n");
scanf_s("%.2f", &emply->emplyRate[i]);
}
}
void calculations(struct input *emply)/*Write a method that calculates the gross, base and overtime pay, pass by reference.*/
{
int i;
for (i = 0; i < 5; i++){
emply->emplyOvrt[i] = (emply->emplyHours[i] > 40)*(emply->emplyRate[i]);
emply->emplyGross[i] = (((emply->emplyHours[i])*(emply->emplyRate[i])) + emply->emplyOvrt[i]);
emply->emplyBase[i] = (emply->emplyGross[i]) - (emply->emplyOvrt[i]);
}
}
void taxes(struct input *emply)/*Write a method that calculates tax, taking as input the gross pay, returning the tax owed.
*/
{
int i;
for (i = 0; i < 5; i++){
emply->emplyTax[i] = ((emply->emplyGross[i])*.2);
}
}
void print(struct input *emply)
{
int i;
for (i = 0; i < 5; i++)
{
printf("Employee Name:%s\n", emply->emplyName[i]);
printf("Hours Worked:%.2f\n ", emply->emplyHours[i]);
printf("Hourly Rate:%.2f\n", emply->emplyRate[i]);
printf("Gross Pay:%.2f\n", emply->emplyGross[i]);
printf("Base Pay:%.2f\n", emply->emplyBase[i]);
printf("Overtime Pay:%.2f\n", emply->emplyOvrt[i]);
printf("Taxes Paid:%.2f\n", emply->emplyTax[i]);
printf("Net Pay:%.2f\n", emply->emplyNet[i]);
}
}

int main(void)
{
struct input payroll = { "",0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f };
employeeInfo(&payroll);
calculations(&payroll);
taxes(&payroll);
print(&payroll);

system("pause");
}

最佳答案

%.2f 不是有效的输入格式说明符(它是输出格式说明符)。尝试仅使用 %f

旁注:assert 语句实际上是在 C 库的实现中,而不是在您的代码中。这就是为什么您会看到令人困惑的行号。

关于c - 调试断言失败,使用 C 的输入格式无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31621050/

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