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

标签 c struct

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

#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/

相关文章:

c - 解释一下这个程序中的esp-ebp

c - 什么是动态回调?

结构体中的 char 数组成员 - 值复制到两个成员

c - 使用c中的结构对数组进行变量赋值的问题

c - 如何使用 c 中的目录打印同月修改的文件?

c - 我不能使用 sprintf()

swift - 为什么可以更改由 let 声明的结构?

c# - 如何在结构中声明一个结构数组?

c++ - C 项目 O 文件在 make 期间删除后仍在寻找 Cpp 文件

C 标记并分析 csv 文件