-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04oct_exp7_2.c
40 lines (33 loc) · 1.12 KB
/
04oct_exp7_2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <string.h>
int main()
{
const int numEmployees = 10;
const float daPercentage = 0.52;
char employeeNames[numEmployees][50]; // array to store employee names
float basicPays[numEmployees]; // array to store basic pays
float grossSalaries[numEmployees]; // array to store gross salaries
// input employee data
for (int i = 0; i < numEmployees; i++)
{
printf("Enter employee %d name: ", i + 1);
fgets(employeeNames[i], 50, stdin);
employeeNames[i][strlen(employeeNames[i]) - 1] = '\0'; // remove newline character
printf("Enter employee %d basic pay: ", i + 1);
char input[20];
fgets(input, 20, stdin);
sscanf(input, "%f", &basicPays[i]);
}
// compute gross salaries
for (int i = 0; i < numEmployees; i++)
{
float da = basicPays[i] * daPercentage;
grossSalaries[i] = basicPays[i] + da;
}
// print employee data
for (int i = 0; i < numEmployees; i++)
{
printf("Employee %d: %s, Gross Salary: %.2f\n", i + 1, employeeNames[i], grossSalaries[i]);
}
return 0;
}