试图创建一个菜单驱动的员工数据程序。我不知道如何创建功能菜单,也无法使菜单选项正常工作,例如编辑先前输入的员工信息。我将不胜感激。当前出现的错误是


编辑员工功能:重新定义;不同的基本类型。
main中,当我使用menu(&payroll)调用菜单函数时,错误消息是无法从input*转换为input
同样在main中-函数employeeInfo(&payroll)给出错误消息,无法从input*转换为input


如果您发现任何其他错误,我敢肯定我还会犯其他错误,请向正确的方向引导我。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//This is a macro intended for use with the emplyName array.
#define SIZE 20

//This struct has all the varibles that I will be using in my functions
typedef struct
{
    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];
}input;

void menu(void);
void employeeInfo(input* emply);
void editEmployees(input* emply);
void print(input* emply);

int main(void)
{
    input payroll={"",0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
    int choice;
    menu(&payroll);
    scanf_s("%d", &choice);
    switch (choice){
    case '1':
        employeeInfo(&payroll);
        break;
    case '2':
        editEmployees(&payroll);
        break;
    case '3':
        break;
    case '4':
        print(&payroll);
        break;
    default:
        printf("Invalid entry\n");
    }
    system("pause");
}

void employeeInfo(input *emply)
{
    int i;

    for (i = 0; i < 5; i++){
        printf("Enter employee name -1 to end.\n");
        scanf_s("%s", &emply->emplyName[i]);
        if (strcmp(emply->emplyName[i], "-1") == 0){
            break;
        }

        printf("Enter employee hours.\n");
        scanf_s("%f", &emply->emplyHours[i]);
        printf("Enter Hourly rate.\n");
        scanf_s("%f", &emply->emplyRate[i]);
    }
}
void calculations(input *emply)/*Write a method that calculates the gross, base and overtime pay, pass by reference.*/
{
    int i;
    i = 0;
    for (i = 0; i < 5; i++){
        if (emply->emplyHours[i] > 40) {
            emply->emplyOvrt[i] = (emply->emplyHours[i] - 40) * (emply->emplyRate[i] * 1.5);
        }
        emply->emplyGross[i] = (((emply->emplyHours[i])*(emply->emplyRate[i])) + emply->emplyOvrt[i]);
        emply->emplyBase[i] = (emply->emplyGross[i]) - (emply->emplyOvrt[i]);
        emply->emplyTax[i] = ((emply->emplyGross[i])*.2);
        emply->emplyNet[i] = (emply->emplyGross[i]) - (emply->emplyTax[i]);
        emply->emplyTotal[0] += emply->emplyGross[i];
    }


}


void print(input *emply)
{
    int i;
    for (i = 0; i < 5; i++)
    {
        if (strcmp(emply->emplyName[i], "-1") == 0){
            break;
        }
        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]);
    }
    printf("Total paid to all employees : %.2f\n", emply->emplyTotal[0]);
}
void editEmployees(input *emply){
    int j;
    int index = 1;
    int i;
    printf("Choose an employee.");
    for (j = 1; j < 5; j++); {
        printf("%d.%s", index, emply->emplyName[j]);
    }
    scanf_s("%d", &i);
    employeeInfo(emply);

}
void menu(void){
    printf("Main Menu\n");
    printf("1. Add Employee\n");
    printf("2. Edit Employee\n");
    printf("3. Print Employee\n");
    printf("4. Print All EMployees\n");
    printf("0. exit\n");

}

最佳答案

从开始


  1.编辑员工功能:重新定义;不同的基本类型。


您需要向前声明函数原型。


  2. menu(&payroll)无法从“输入*”转换为“输入”。


您的函数声明和定义不匹配。


在声明中,您有void menu(input payroll);
在定义上,您有void menu(void){ //
你用menu(&payroll);打电话


以上三个都不同。坚持任何一个。


  3. employeeInfo(&payroll)无法从“输入*”转换为“输入”。


同样,函数声明和定义之间不匹配。更改您的函数声明

void employeeInfo(input payroll);




void employeeInfo(input* payroll);

08-16 14:03