How to update Employee Salary in C?


(Sangsoo Ha) #1

I am having difficulty with creating a new case(case#3) which update pre-entered employees’ data.
What could have gone wrong?
The question is:

  • Prompt the user for the employee identification number using a do-while loop. While the number is not found in the employee array, keep prompting the user.
  • Once the number is found, display the current salary for the employee with that identification number and prompt the user to input the new salary. Replace the old salary with the input value.


#include <stdio.h>
#define SIZE 4

struct employee_data{
int Age;
int Int_Num;
double Salary;

int main(void){

int option = 0;
int NOE = 0;
printf("—=== EMPLOYEE DATA ===—\n");enter code here

struct employee_data emp[SIZE];
// Employee_ID
int i;
do {
// Print the option list
printf("\n1. Display Employee Information\n");
printf(“2. Add Employee\n”);

    printf("3. Update Employee Salary\n");
    printf("4. Remove Employee\n");
    printf("0. Exit\n\n");
    printf("Please select from the above options: ");

    // Capture input to option variable

    switch (option) {
    case 0: // Exit the program
            printf("Exiting Employee Data Program. Good Bye!!!\n");
    case 1: // Display Employee Data
                    // @IN-LAB

            printf("EMP ID  EMP AGE EMP SALARY\n");
            printf("======  ======= ==========\n");
             for (i=0; i<SIZE; i++){
            printf("%6d%9d%11.2lf\n", emp[i].Int_Num, emp[i].Age,emp[i]
           // /printf("\n");
          //  printf("%6d%9d%11.2lf", emp[1].Age, emp[1].Int_Num,emp[1]
            // Use "%6d%9d%11.2lf" formatting in a
            // printf statement to display
            // employee id, age and salary of
            // all  employees using a loop construct

            // The loop construct will be run for SIZE times
            // and will only display Employee data
            // where the EmployeeID is > 0
           // printf("\n");
    case 2: // Adding Employee

            // @IN-LAB

    //   for (i = 0; i < SIZE; i++)
            printf("Adding Employee\n");
              if(NOE < SIZE){

             // printf("ERROR!!! Maximum Number of Employees Reached\n"
            printf("Enter Employee ID: ");
            scanf("%d", &emp[NOE].Int_Num);
            printf("Enter Employee Age: ");
            scanf("%d", &emp[NOE].Age);
            printf("Enter Employee Salary: ");
            scanf("%11lf", &emp[NOE].Salary);


             printf("ERROR!!! Maximum Number of Employees Reached\n");
            // Check for limits on the array and add employee
            // data accordingly.}


              int number = 0;
    case 3: printf("Update Employee Salary\n");

                printf("Enter Employee ID: ");
                scanf("%d", &number);
                if(number == emp[NOE].Int_Num){
                printf("The current salary is %11lf", emp[NOE].Salary);

               //  else{
            }while (number != emp[NOE].Int_Num);

(Asnaf Shaikh) #2

I want the hole program