1. 用结构体存放如下表中的数据,然后输出每个人的姓名和实发工资(实发工资=基本工资+浮动工资-支出)
姓名 |
基本工资 |
浮动工资 |
支出 |
Tom |
1240.00 |
800.00 |
75.00 |
Lucy |
1360.00 |
900.00 |
50.00 |
Jack |
1560.00 |
1000.00 |
80.00 |
程序代码:
#include <stdio.h>
// 定义结构体
typedef struct {
char name[20];
float baseSalary;
float floatingSalary;
float expenditure;
} Employee;
// 计算并输出每个人的实发工资
void calculateSalary(Employee emp) {
float netSalary = emp.baseSalary + emp.floatingSalary - emp.expenditure;
printf("姓名: %s, 实发工资: %.2f\n", emp.name, netSalary);
}
int main() {
// 创建并初始化结构体数组
Employee employees[3] = {
{"Tom", 1240.00, 800.00, 75.00},
{"Lucy", 1360.00, 900.00, 50.00},
{"Jack", 1560.00, 1000.00, 80.00}
};
// 遍历数组,计算每个人的实发工资
for (int i = 0; i < 3; i++) {
calculateSalary(employees[i]);
}
return 0;
}
标签:发工资,浮动工资,11.21,float,emp,基本工资,Employee From: https://www.cnblogs.com/lml66/p/17909393.html