一家筆記型電腦製造公司對其銷售人員的月度薪酬政策如下-
最低基本工資: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") ; scanf("%d %f", &quantity, &price) ; bonus = BONUS_RATE * quantity ; commission = COMMISSION * quantity * price ; gross_salary = BASIC_SALARY + bonus + commission ; printf("
"); printf("Bonus = %6.2f
", bonus) ; printf("Commission = %6.2f
", commission) ; printf("Gross salary = %6.2f
", gross_salary) ; }
執行上述程式時,會產生下列輸出-
Number of items sold and their price 20 150000 Bonus = 4000.00 Commission = 150000.00 Gross salary = 157000.00
以上是C程式用巨集函數計算銷售員的薪資的詳細內容。更多資訊請關注PHP中文網其他相關文章!