当我想添加新员工时,这不会给我带来小麻烦

时间:2019-06-18 02:19:37

标签: c

所以我遇到了一个我无法解决的小错误。我有这个小程序,它正在工作,但是如果我增加了4名员工,而我删除了1名员工,那么我尝试增加另一名员工。它不允许我,SIZE是4,所以应该让我这样做。 这是一个很小的错误,但我找不到解决方法。/

#define SIZE 4

        case 2: // Adding Employee
                // @IN-LAB
            printf("Adding Employee\n");
            printf("===============\n");
            // Check for limits on the array and add employee
            // data accordingly.
            if (empCount < 4) {
                printf("Enter Employee ID: ");
                scanf("%d", &emp[empCount].id);
                printf("Enter Employee Age: ");
                scanf("%d", &emp[empCount].age);
                printf("Enter Employee Salary: ");
                scanf("%lf", &emp[empCount].salary);
                printf("\n");
                if (emp[empCount].id > 0) {
                    empCount++;
                }
            }
            else
                printf("ERROR!!! Maximum Number of Employees Reached\n\n");
            break;
        case 4:
            printf("Remove Employee\n");
            printf("===============\n");
            do {
                printf("Enter Employee ID: ");
                scanf("%d", &empId);
                for (k = 0; k < empCount; k++) {
                    if (emp[k].id == empId) {
                        printf("Employee %d will be removed\n\n", empId);
                        emp[k].id = 0;
                        k = empCount;
                        empFound = 1;
                    }
                }
                if (empFound == 0) {
                    printf("*** ERROR: Employee ID not found! ***\n");
                }
            } while (empFound != 1);
            break;
        default:
            printf("ERROR: Incorrect Option: Try Again\n\n");
        }
    } while (option != 0);
    printf("Exiting Employee Data Program. Good Bye!!!\n\n");
    return 0;
}

完整代码在这里https://pastebin.com/bZSb72E5

0 个答案:

没有答案