第十一讲 练习代码

第十一讲  分支结构

 

 

 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace ConsoleApp7

{

    class Product

    {

        public string name;       //名称

        public decimal price;     //价格

        public int amout;         //数量

        public bool discontinued; //停售

    }

 

    public enum Department

    {

        行政部,

        财务部,

        人事部,

        市场部

    }

    class Employee

    {

        public string name;

        public decimal salary;

        public string gender;

        public Department department;

    }

    class Program

    {

        static void Main(string[] args)

        {

            //if语句

            Product p = new Product();

            p.name = "iPhone12";

            p.price = 9800.00m;

            p.amout = 30;

            p.discontinued = false;

 

           //1.if

            if(p.amout<0)  //条件表达式

            {

                p.discontinued = true;//子语句

            }

            //2.if  .... else....

            string result = "";

            if(p.amout<=0)

            {

                result = "已售空!";

            }

            else

            {

                result = "剩余" + p.amout + "件";

            }

            Console.WriteLine(result);

            Console.ReadLine();

 

            //3.if  .... else if ....  else....

            //低于3000不打折,3000-5000九折,5000-8000八折,8000以上七折

 

            decimal newPrice = 0.0m;

            if (p.price <= 3000)

            {

                newPrice = p.price;

            }

            else if (p.price <= 5000)

            {

                newPrice = p.price * 0.9m;

            }

            else if (p.price <= 80000)

            {

                newPrice = p.price * 0.8m;

 

            }

            else

                newPrice = p.price * 0.7m;

            Console.WriteLine(newPrice);

            Console.ReadLine();

 

 

            //switch语句(多重分支)

 

            Employee emp = new Employee();

            emp.name = "TOM";

            emp.salary = 3650.00m;

            emp.gender = "男";

            emp.department = Department.市场部;

            switch(emp.gender)

            {

                case "男":

                    emp.salary += 500;

                    break;

                case "女":

                    emp.salary += 1000;

                    break;

            }

 

            //根据所在部门调整薪资

            switch (emp.department)  //括号里一定要是常量

            {

                case Department.人事部:   

                    emp.salary += 500;

                    break;            //每一种情况后,break 一定要有。

                case Department.市场部:

                    emp.salary += 600;

                    break;

                case Department.行政部:

                    emp.salary += 800;

                    break;

                case Department.财务部:

                    emp.salary += 1000;

                    break;

                default:

                    emp.salary += 100;

                    break;

            }

 

            Console.WriteLine("{0}的工资是:{1},他的部门是:{2}", emp.name, emp.salary,emp.department);

            Console.ReadLine();

 

            //练习

            //1.计算个人所得税,假设个人所得税为:税率 *(工资 - 1600)。请编写程序计算应缴的所得税,其中税率定义为:

            //(1)当工资不超过1600时,税率为0;

            //(2)当工资在区间(1600,2500]时,税率为5 %;

            //(3)当工资在区间(2500,3500]时,税率为10 %;

            //(4)当工资在区间(3500,4500]时,税率为15 %;

            //(5)当工资超过4500时,税率为20 %。

            //2.企业发放的奖金根据利润提成。利润(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,求应发放奖金总数?

 

        }

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海棠弯弯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值