程序12

 【程序12】

程序12 题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万 元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%;20万到40万之间时,高于20万元的部 分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可 提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数? 1.程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。

 

 1         var reward = 0;
 2         function sumReward(profit) {
 3             if (profit > 1000000) {  
 4                 reward = (profit - 1000000) * 0.01;
 5             }
 6             if (profit > 600000) {
 7                 if (profit > 1000000) {
 8                     profit = 1000000;
 9                 }
10                 reward = reward + (profit - 600000) * 0.015;
11             }
12             if (profit > 400000) {
13                 if (profit > 600000) {
14                     profit = 600000;
15                 }
16                 reward = reward + (profit - 400000) * 0.03;
17             }
18             if (profit > 200000) { 
19                 if (profit > 400000) {
20                     profit = 400000;
21                 }
22                 reward = reward + (profit - 200000) * 0.05;
23             }
24             if (profit > 100000) {
25                 if (profit > 200000) {
26                     profit = 200000;
27                 }
28                 reward = reward + (profit - 100000) * 0.075;
29             }
30             if (profit > 0) {
31                 if (profit > 100000) {
32                     profit = 100000;
33                 }
34                 reward = reward + profit * 0.1;
35             }
36             return reward;
37         }

 

 

 

posted @ 2012-06-24 20:40  前端咖  阅读(290)  评论(0编辑  收藏  举报