Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Need Some help

+1 vote
asked Oct 17, 2018 by Qibs (270 points)
CODE:

https://onlinegdb.com/HkkM2AXiX

I need this:

https://imgur.com/a/0GRN3D4

How do I print the employee salary and the new salary...I've tried so many things it doesn't work. If anyone can provide a code I would appreciate it.

2 Answers

0 votes
answered Oct 17, 2018 by anonymous
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#define SIZE 4

struct Employee {
    int id,
        age;

    double salary;
};

int main(void) {

    int menuChoice,
        i,
        validEmployees = 0,
        idToUpdate = 0;
 
    struct Employee emp[SIZE] = { {0} };
    int empid[SIZE] = {1,2,3,4},
        empsal[SIZE] = {100,200,300,400},
        empage[SIZE] = {23,24,25,26};
        
    /*create a  database
    Employee_ID    Salaray
    1              500
    2              1000
   */

   for(i =0 ; i < SIZE ; i++)
   {
       emp[i].id = empid[i];
       emp[i].salary = empsal[i];
       emp[i].age = empage[i];
       
   }
    printf("---=== EMPLOYEE DATA ===---\n");
    do {
        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: ");
        scanf("%d", &menuChoice);
        switch (menuChoice) {
        case 1:
            printf("\nEMP ID  EMP AGE EMP SALARY\n");
            printf("======  ======= ==========\n");
            for (i = 0; i < SIZE; i++) {
                if (emp[i].id >= 0) {
                    printf("%6d%9d%11.2lf\n", emp[i].id, emp[i].age, emp[i].salary);
                }
            }

            break;
        case 2:
            printf("\nAdding Employee\n");
            printf("===============");
            validEmployees = 0;

            for (i = 0; i < SIZE; i++) {
                if (emp[i].id > 0) {
                    ++validEmployees;
                }
            }

            if (validEmployees >= SIZE) {
                printf("\nERROR!!! Maximum Number of Employees Reached\n");
            }
            else {
                printf("\nEnter Employee ID: ");
                scanf("%d", &emp[validEmployees].id);
                printf("Enter Employee Age: ");
                scanf("%d", &emp[validEmployees].age);
                printf("Enter Employee Salary: ");
                scanf("%lf", &emp[validEmployees].salary);
            }
            break;

        case 3:

            printf("\nUpdate Employee Salary\n");
            printf("======================\n");
            printf("Enter Employee ID: ");
            scanf("%d", &idToUpdate);

            for (i = 0; i < 2; i++) {
                if (emp[i].id <= 0)
                {
                    printf("*** ERROR: Employee ID Not found! ***\n");
                    printf("Enter Employee ID: ");
                    scanf("%d", &idToUpdate);
                }
            }

            for (i = 0; i < SIZE; i++) {
                if (idToUpdate == emp[i].id) {
                    printf("The current salary is %.2lf", emp[i].salary);
                    printf("\nEnter Employee New Salary: ");
                    scanf("%lf", &emp[i].salary);
                }
            }

            break;

        case 4:

            printf("\nRemove Employee\n");
            printf("===============\n");
            printf("Enter Employee ID: ");
            scanf("%d", &idToUpdate);

            for (i = 0; i < SIZE; i++) {
                if (idToUpdate == emp[i].id) {
                    printf("Employee %d will be removed\n", emp[i].id);
                    emp[i].id = 0;
                }
            }
            break;

        case 0:

            printf("\nExiting Employee Data Program. Good Bye!!!\n");

            break;
        default:

            printf("\nERROR: Incorrect Option: Try Again\n");

            break;
        }

    } while (menuChoice != 0);

    return 0;
}
commented Oct 17, 2018 by Qibs (270 points)
Its not working...I cant type 2 to add employees cause its maxed employees...
commented Oct 17, 2018 by Qibs (270 points)
The code is not what I asked for....
commented Oct 17, 2018 by Qibs (270 points)
I just want a code that will display current salary and the Employee New Salary after you type in 3 incorrect employee id's:

123
321
333

*This should be there the salaries go*
commented Oct 26, 2019 by bushra solangi (140 points)
yeah it can work  if you change the defined size 4 to 10 (or else )
0 votes
answered Oct 17, 2018 by Obed Batchu (140 points)
Getting struck while doing coding
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...