-4

这是问题:

编写一个交互式程序,为在一家小型化学零售店工作的 12 名员工(2 名员工是文员,1 名计算机操作员,6 名销售员,3 名助手)生成工资单。可以在必要时进行假设。工资单应显示员工编号、员工姓名、编号。当月的工作天数、工资单的生成日期、支付工资的月份、支付的所有细节、扣除额、总工资和净工资。

当我运行程序时,它说指针无效,即使我没有使用过指针,谁能告诉我这个程序有什么错误?

 #include <time.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>

    char name[30][30], designation[20[20], empid[12][12];
    int i;
    int n = 12;
    int working_days = 27;
    float basic[12], days_absent[12], days_present[12], gross_salary[20], pf[12], allowance[12], net[12];

    void enter_details_of_employee();
    void display();
    void get_time();

    void main()
    {
    int k;
    printf("Enter 1 to enter employee details and 2 to display salary\n");
    scanf("%d", &k);

    if(k == 1)
    {
    enter_details_of_employee();
    }
    else if(k == 2)
    {
    display();
    get_time();
    }
    else
    {
    printf("invalid choice");
    }
    }


    void enter_details_of_employee ()
    {
    int choice;
    int clerk_counter = 0, operator_counter = 0, salesman_counter = 0, helper_counter = 0, max = 0;

    do {

    printf("\n enter details of employees\n");

    printf("enter employee name\n");
    scanf("%c", &name);

    printf("enter employee id\n");
    scanf("%c", &empid);

    printf("enter your choice for employee designation\n 1.clerk \n 2.computer operator\n 3. salesman\n 4.helper\n");
    scanf("%d", &choice);

    if (choice == 1)
    {
    if(clerk_counter == 2)
            {
                printf("sorry, you have already entered the details of all clerks\n");
            }

                else

            {
                designation = "clerk";
                basic = 8000.00;
                printf("enter no of days absent\n");
                scanf("%d", &days_absent);
                days_present = working_days - days_absent;
                gross_salary = basic - ((days_absent / working_days) * basic);
                pf = gross_salary*0.1;
                allowance = gross_salary*0.55;
                net = (gross - pf) + allowance;
                clerk_counter++;

            }



        }
        else if (choice == 2)
        {
                if(operator_counter == 1)
            {
                printf("sorry, you have already entered the details of all computer operators\n");
            }

                else

            {
                designation = "computer operator";
                basic = 9000;
                printf("enter no of days absent\n);
                scanf("%d", &days_absent);
                days_present = working_days - days_absent;
                gross_salary = basic - ((days_absent / working_days) * basic);
                pf = gross_salary*0.12;
                allowance = gross_salary*0.75;
                net = (gross - pf) + allowance;
                operator_counter++;

            }


        }

        else if (choice == 3)
        {
                if(salesman_counter == 6)
            {
                printf("sorry, you have already entered the details of all salesman\n");
            }

                else

            {
                designation = "salesman";
                basic = 10000;
                printf("enter no of days absent\n);
                scanf("%d", &days_absent);
                days_present = working_days - days_absent;
                gross_salary = basic - ((days_absent / working_days) * basic);
                pf = gross_salary*0.15;
                allowance = gross_salary*0.95;
                net = (gross - pf) + allowance;
                salesman_counter++;

            }


        }

    else if (choice == 4)
        {
                if(salesman_counter == 3)
            {
                printf("sorry, you have already entered the details of all helpers\n");
            }

                else

            {
                designation = "helper";
                basic = 6500;
                printf("enter no of days absent\n);
                scanf("%d", &days_absent);
                days_present = working_days - days_absent;
                gross_salary = basic - ((days_absent / working_days) * basic);
                pf = gross_salary*0.08;
                allowance = gross_salary*0.45;
                net = (gross - pf) + allowance;
                helper_counter++;

            }


    }

    else
        {
    printf("invalid choice");
        }

        }
        while (max!=12);
        }

    void get_time()
    {
    time_t t = time(NULL);
    struct tm tm = *localtime(&t);

    printf("now: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
    }

    void display()
    {
    printf("SALARY SLIP OF EMPLOYEES ";
    printf("---------------------------------------------------------------------------------------------------");
    printf("empid\t name\t days_absent\t days_present\t gross_salary\t   PF\t allowance\t net");
    printf("---------------------------------------------------------------------------------------------------");

    for(i=0;i<n;i++)
    {
        printf(empid[i][i] name[i][i] basic[i] days_absent[i] days_present[i] gross_salary[i] pf[i] allowance[i] net);
    }

    }
4

2 回答 2

0
here is a modified program, any feedback??

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

typedef struct mystruct{
char name[30];
char designation[20];
char empid[8];
float basic;
float days_absent;
float days_present;
float gross_salary;
float pf;
float allowance;
float net;
int counter;
int clerk_counter;
int operator_counter;
int salesman_counter;
int helper_counter;
char *next;
}mystruct;

char *p;


void enter_details_of_employee();
void display();
void get_time();

void main()
{
do
{
int k, choice;
printf("Enter 1 to enter employee details and 2 to display salary\n");
scanf("%d", &k);

if(k == 1)
{
p = (mystruct*)malloc(sizeOf(mystruct));
enter_details_of_employee();
}
else if(k == 2)
{
display();
get_time();
}
else
{
choice = 0;
printf("invalid choice, press 1 to continue\n");
}
}
while choice == 1;
}

void enter_details_of_employee ()
{
if(p->mystruct.counter!=12)
{
int proceed = 1;

do
{
printf("\n enter details of employees\n");

printf("enter employee name\n");
scanf("%u", &p->mystruct.name);

printf("enter employee id\n");
scanf("%u", &p.empid);

printf("enter your choice for employee designation\n 1.clerk \n 2.computer operator\n 3. salesman\n 4.helper\n");
scanf("%d", &choice);

if (choice == 1)
{
if(p->mystruct.clerk_counter == 2)
        {
            printf("sorry, you have already entered the details of all clerks\n");
        }

            else

        {
            p->mystruct.designation = "clerk";
            p->mystruct.basic = 8000.00;
            printf("enter no of days absent\n");
            scanf("%u", &p->mystruct.days_absent);
            p->mystruct.days_present = p->mystruct.working_days - p->mystruct.days_absent;
            p->mystruct.gross_salary = p->mystruct.basic - ((p->mystruct.days_absent / p->mystruct.working_days) * p->mystruct.basic);
            p->mystruct.pf = p->mystruct.gross_salary*0.1;
            p->mystruct.allowance = p->mystruct.gross_salary*0.55;
            p->mystruct.net = (p->mystruct.gross - p->mystruct.pf) + p->mystruct.allowance;
            p->mystruct.clerk_counter++;
            p->mystruct.counter++;
        }



    }
    else if (choice == 2)
    {
            if(p->mystruct.operator_counter == 1)
        {
            printf("sorry, you have already entered the details of all computer operators\n");
        }

            else

        {
            p->mystruct.designation = "computer operator";
            p->mystruct.basic = 9000;
            printf("enter no of days absent\n);
            scanf("%u", &p->mystruct.days_absent);
            p->mystruct.days_present = p->mystruct.working_days - p->mystruct.days_absent;
            p->mystruct.gross_salary = p->mystruct.basic - ((p->mystruct.days_absent / p->mystruct.working_days) * p->mystruct.basic);
            p->mystruct.pf = p->mystruct.gross_salary*0.12;
            p->mystruct.allowance = p->mystruct.gross_salary*0.75;
            p->mystruct.net = (p->mystruct.gross - p->mystruct.pf) + p->mystruct.allowance;
            p->mystruct.operator_counter++;
            p->mystruct.counter++;      
        }


    }

    else if (choice == 3)
    {
            if(p->mystruct.salesman_counter == 6)
        {
            printf("sorry, you have already entered the details of all salesman\n");
        }

            else

        {
            p->mystruct.designation = "salesman";
            p->mystruct.basic = 10000;
            printf("enter no of days absent\n");
            scanf("%u", &p->mystruct.days_absent);
            p->mystruct.days_present = p->mystruct.working_days - p->mystruct.days_absent;
            p->mystruct.gross_salary = p->mystruct.basic - ((p->mystruct.days_absent / p->mystruct.working_days) * p->mystruct.basic);
            p->mystruct.pf = p->mystruct.gross_salary*0.15;
            p->mystruct.allowance = p->mystruct.gross_salary*0.95;
            p->mystruct.net = (p->mystruct.gross - p->mystruct.pf) + p->mystruct.allowance;
            p->mystruct.salesman_counter++;
            p->mystruct.oounter++;      
        }


    }

else if (choice == 4)
    {
            if(p.->mystruct.salesman_counter == 3)
        {
            printf("sorry, you have already entered the details of all helpers\n");
        }

            else

        {
            p->mystruct.designation = "helper";
            p->mystruct.basic = 6500;
            printf("enter no of days absent\n);
            scanf("%u", &p->mystruct.days_absent);
            p->mystruct.days_present = p->mystruct.working_days - p->mystruct.days_absent;
            p->mystruct.gross_salary = p->mystruct.basic - ((p->mystruct.days_absent / p->mystruct.working_days) * p->mystruct.basic);
            p->mystruct.pf = p->mystruct.gross_salary*0.08;
            p->mystruct.allowance = p->mystruct.gross_salary*0.45;
            p->mystruct.net = (p->mystruct.gross - p->mystruct.pf) + p->mystruct.allowance;
            p->mystruct.helper_counter++;
            p->mystruct.counter++;      
        }


}

else
    {
printf("invalid choice, press 1 to continue\n");
scanf("%d", &proceed);
    }
        while (proceed);
    }
    }
    else 
    {
    printf("data entry complete");
    }
    }


}
void get_time()
{
time_t t = time(NULL);
struct tm tm = *localtime(&t);

printf("now: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
}

void display()
{
printf("SALARY SLIP OF EMPLOYEES ";
printf("---------------------------------------------------------------------------------------------------");
printf("empid\t name\t days_absent\t days_present\t gross_salary\t   PF\t allowance\t net");
printf("---------------------------------------------------------------------------------------------------");
while(p.next!=NULL);
{
print(p.mystruct);
}
}
于 2013-09-14T06:57:36.343 回答
0

错误:

1) 语法错误 1:

char name[30][30], designation[20[20], empid[12][12];  // Bracket mismatch

2) 语法错误 2:

char designation[20[20];
designation = "clerk";    // What is this?? ..the invalid pointer error

3)自己休息或尝试使用-Wall选项编译。

于 2013-09-13T11:22:54.733 回答