Here is the question that I have to do Implement an employee salary management s
ID: 3561908 • Letter: H
Question
Here is the question that I have to do
Implement an employee salary management system using C language, employee information includes: employee number, name, date, salary. (employee number is unique).
Question 1: salary input: input employee salary.
Question 2: salary enquiry: browse employee salary by name and date.
Question 3: employee list: output employee by annual salary.
Question 4: employee delete: delete an employee record by user input.
What I have done so far,hopefully it is the right thing is Q 3 and Q 1 ..but I could not get how to do search and delete please help me .
P.s (While) doesnt work for me i dont know why to repeat the program again and again
===============================================
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct Employee
{
char name[40];
char date[10];
int id;
float salary;
} Employee;
int main()
{
Employee emp;
char another, choice;
printf("(a) Add Employee");
printf(" ");
printf("(b) List Employees");
printf(" ");
scanf("%c",&choice);
switch(choice)
{
case'a':
another='Y';
while(another=='Y'||another=='Y')
{
printf("Enter Employee's Name : ");
scanf("%s", &emp.name);
printf("Enter the date: ");
scanf("%s", &emp.date);
printf("Enter the ID: ");
scanf("%d", &emp.id);
printf("Enter the salary: ");
scanf("%f",&emp.salary);
printf("Add another Employee Y/N");
scanf("%c",&another);
}
break;
case'b':
another='Y';
while(another=='Y'||another=='Y')
{
printf("No. Name Date Salary");
printf("...............................................");
printf("%d",emp.id );
printf(" ");
printf("%s",emp.name);
printf(" ");
printf("%s",emp.date);
printf(" ");
printf("%f",emp.salary);
printf("Add another Employee Y/N");
scanf("%c",&another);
//another=getchar();
}
break;
}
return 0;
}
Explanation / Answer
/*considering array of emp structures emp[100] */
void search(Employee *emp)
{
int i=0;
printf("enter name,date");
scanf("%s %s",&name,&date);
while(i<100)
{
if(strcmp(emp[i].name,name)==0 && strcmp(emp[i].date,date)==0 )
{
printf("salary : %d",emp[i].salary);
}
i++;
}
}
Employee * delete (Employee *emp)
{
int i=0;
char *name;
printf("enter name of employee");
scanf("%s",&name);
while(i<n)
{
if(strcmp(emp[i].name,name)==0)
{
while(i<n)
emp[i]=emp[i+1];i++;
}
}
}