基于%的奖金制度

时间:2013-12-24 10:57:48

标签: if-statement formula

我正在寻求你对奖励制度公式的帮助。 目标最低销售额为180,000,我想按如下方式计算奖金:

under 180,000 = zero bonus
180,000 to 210,000 = 2% bonus of the sales 
210,000 and above = 4% bonus of sales

因此,如果达到250,000,则180,000以下的金额为零; 180,000和210,000之间30,000的2%奖励和210,000以上40,000的4%奖励等于:

2% of 30,000  = 600
4% of 50,000 = 2000

Total bonus = 2600

I have tried to use some of the IF equations on this site, but cannot seem to work it out. 

提前致谢。

2 个答案:

答案 0 :(得分:0)

取一个变量说int sal;为它分配值并像这样检查yor if-else语句应如下所示。

修改 接受变量说int bonus = 0;

if(sal <= 18000) {
  // No Bonus  
  bonus = 0;    
} else if (sal > 18000 && sal < 21000) {
  // Do calculation for 2%
  bonus = (sal)*.02;
} else if(sal > 21000){
// Do calculation for 4%
   bonus = (sal)*.04;
}

这将为您提供按工资总额计算的奖金金额。

谢谢

答案 1 :(得分:0)

尝试这样的事情 - 它是伪代码

maxSales = 10000000000000000000

def calcBonus(x, bonusSystem):
    totalBonus = 0
    lowBase = 0
    for hiBase, percentage in bonusSystem:
        if (lowBase < x):
            totalBonus += (min(x,hiBase) - lowBase) * percentage
            lowBase = hiBase
    return totalBonus

bonusSystem = [(180000, 0), (210000,.02), (maxSales, .05)]
sales = 250000
print calcBonus(sales, bonusSystem)