golang99道练习题之02

栏目: Go · 发布时间: 7年前

内容简介:或者

题目:企业发放的奖金根据利润提成。

利润(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%提成从键盘输入当月利润,求应发放奖金总数?

1.程序分析:请利用数轴来分界,定位。

2.程序源代码:

package main
import "fmt"

func main() {
	var bonus,bonus1 float64
	fmt.Println("请输入利润金额:")
	fmt.Scan(&bonus)
	if bonus <=100000 {
		bonus1 = bonus * 0.1
		fmt.Println("您的奖金是:",bonus1)
	}else if bonus<=200000 {
		bonus1 = 100000 * 0.1+(bonus-100000)*0.075
		fmt.Println("您的奖金是:",bonus1)
	}else if bonus<=400000 {
		bonus1 = 100000 * 0.1+100000*0.075+(bonus-200000)*0.05
		fmt.Println("您的奖金是:",bonus1)
	}else if bonus<=600000 {
		bonus1 = 100000 * 0.1+100000*0.075+200000*0.05+(bonus-400000)*0.03
		fmt.Println("您的奖金是:",bonus1)
	}else if bonus<=1000000 {
		bonus1 = 100000 * 0.1+100000*0.075+200000*0.05+200000*0.03+(bonus-600000)*0.015
		fmt.Println("您的奖金是:",bonus1)
	}else if bonus>1000000 {
		bonus1 = 100000 * 0.1+100000*0.075+200000*0.05+200000*0.03+400000*0.15+(bonus-1000000)*0.01
		fmt.Println("您的奖金是:",bonus1)
	}
}

或者

package main

import "fmt"

func main() {

	bonus10w := 100000 * 0.1
	bonus20w := bonus10w + 100000*0.075
	bonus40w := bonus20w + 200000*0.05
	bonus60w := bonus40w + 200000*0.03
	bonus100w := bonus60w + 400000*0.015

	var bonus, bonus1 float64
	fmt.Println("请输入利润金额:")
	fmt.Scan(&bonus)

	if bonus <= 100000 {
		bonus1 = bonus * 0.1
		fmt.Println("您的奖金是:", bonus1)
	} else if bonus <= 200000 {
		bonus1 = bonus10w + (bonus-100000)*0.075
		fmt.Println("您的奖金是:", bonus1)
	} else if bonus <= 400000 {
		bonus1 = bonus20w + (bonus-200000)*0.05
		fmt.Println("您的奖金是:", bonus1)
	} else if bonus <= 600000 {
		bonus1 = bonus40w + (bonus-400000)*0.03
		fmt.Println("您的奖金是:", bonus1)
	} else if bonus <= 1000000 {
		bonus1 = bonus60w + (bonus-600000)*0.015
		fmt.Println("您的奖金是:", bonus1)
	} else if bonus > 1000000 {
		bonus1 = bonus100w + (bonus-1000000)*0.01
		fmt.Println("您的奖金是:", bonus1)
	}
}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Approximation Algorithms

Approximation Algorithms

Vijay V. Vazirani / Springer / 2001-07-02 / USD 54.95

'This book covers the dominant theoretical approaches to the approximate solution of hard combinatorial optimization and enumeration problems. It contains elegant combinatorial theory, useful and inte......一起来看看 《Approximation Algorithms》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具