用宏函数计算销售员工资的C程序。
问题
笔记本电脑制造公司为其销售人员制定了月度补偿政策,如下所述-
最低基本工资:3000.00
每售出一台电脑的奖金:200.00
每月总销售额的佣金:5%
由于笔记本电脑的价格不断变化,每台笔记本电脑的销售价格固定在每个月初。
解决方案
查找奖金和佣金的逻辑如下-
bonus = BONUS_RATE * quantity ; commission = COMMISSION * quantity * price ;
总工资是通过使用下面给出的公式计算的-
Gross salary = basic salary + (quantity * bonus rate) + (quantity * Price) * commission rate
示例
以下是使用宏函数计算销售人员工资的C程序-
#define BASIC_SALARY 3000.00 #define BONUS_RATE 200.00 #define COMMISSION 0.05 main(){ int quantity ; float gross_salary, price ; float bonus, commission ; printf("number of items sold and their price\n") ; scanf("%d %f", &quantity, &price) ; bonus = BONUS_RATE * quantity ; commission = COMMISSION * quantity * price ; gross_salary = BASIC_SALARY + bonus + commission ; printf("\n"); printf("Bonus = %6.2f\n", bonus) ; printf("Commission = %6.2f\n", commission) ; printf("Gross salary = %6.2f\n", gross_salary) ; }输出结果
执行上述程序时,它会产生以下输出-
Number of items sold and their price 20 150000 Bonus = 4000.00 Commission = 150000.00 Gross salary = 157000.00