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

时间:2015-07-24 23:01:50

标签: 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");
    }

1 个答案:

答案 0 :(得分:0)

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

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