Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int position =0;
- struct Employee
- {
- char name[20], phoneNo[12];
- float salary;
- };
- int main()
- {
- int N;
- char choice;
- printf("Enter the size of the array : ");
- scanf("%d", &N);
- struct Employee e[N];
- printf("\n======= Office Pay Roll System =========\n");
- printf("Enter 'x', to take information of all employee into the Employee structure array of size N.\n");
- printf("Enter 'y', to find and display the info of employee with the highest salary.\n");
- printf("Enter 'z', to display the information of employees with less than half of the highest salary in tabular format.\n");
- printf("Enter 'q', to quit/exit the menu system\n");
- while (1)
- {
- getchar();
- printf("\nEnter your choice: ");
- scanf("%c", &choice);
- if (choice == 'q')
- {printf("\nProcess end...\n");
- break;}
- switch (choice)
- {
- case 'x':
- {
- takeEmployeesInfoFromKeyboard(e, N);
- break;
- }
- case 'y':
- {
- findEmployeeWithHighestSalary(e, N);
- break;
- }
- case 'z':
- {
- displayAllEmployeesInfo(e, N);
- break;
- }
- default:
- {
- printf("Invalid Input. \n ");
- break;
- }
- }
- }
- return 0;
- }
- void takeEmployeesInfoFromKeyboard(struct Employee e[], int n)
- {
- int i;
- for (i = 0; i < n; i++)
- {
- printf("\n Employee no %d : ", i + 1);
- printf("\n Enter name of employee - ");
- scanf("%s", e[i].name);
- printf(" Enter Phone No of employee - ");
- scanf("%s", e[i].phoneNo);
- printf(" Enter salary of employee - ");
- scanf("%f", &e[i].salary);
- }
- }
- void findEmployeeWithHighestSalary(struct Employee e[], int n)
- {
- int i;
- float Highest = e[0].salary;
- printf("\n Employee with highest salary :");
- for (i = 1; i < n; i++)
- {
- if (Highest < e[i].salary)
- {
- Highest = e[i].salary;
- position = i;
- }
- }
- printf("\n Name : %s\n Phone NO :%s\n Salary : %.2f\n", e[position].name, e[position].phoneNo, e[position].salary);
- }
- void displayAllEmployeesInfo(struct Employee e[], int n )
- {
- int i;
- float half = e[position].salary/2;//position is globally declared.
- printf("\n\n Employees’ information whose salary is less than half of the highest salary :");
- printf("\n\n Employee Name Employee Phone No Salary\n");
- for (i = 0; i < n; i++)
- {
- if (e[i].salary < half)
- {
- printf(" %s\t\t%s\t\t%.2f\n", e[i].name, e[i].phoneNo, e[i].salary);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement