• UT源码 063


    设计佣金问题的程序

    commission方法是用来计算销售佣金的需求,手机配件的销售商,手机配件有耳机(headphone)、手机壳(Mobile phone shell)、手机贴膜(Cellphone screen protector)三个部件,每个部件单价为:耳机80元,手机壳10元,手机贴膜8元,每月月末向制造商报告销量,制造商根据销量给销售商佣金。如果销售额不足1000元按10%提取佣金,1000-1800元部分按15%提取佣金,超过1800元部分按20%提取佣金。

    程序要求:

    1)先显示“请分别输入三种手机配件的销售情况:”

    2)不满足条件,返回:“输入数量不满足要求”,返回重新输入;

    3)条件均满足, 则返回佣金额。返回等待输入。

    float  commission (int headphone, int shell, int protector)

    #include"cstdio"
    #include"iostream"
    #include"algorithm"
    #include"cstring"
    #include"cmath"
    using namespace std;
    float commission(int headphone, int shell, int protector)
    {
        if(headphone<0 || shell<0 || protector<0)
            return -1.0f;
        long long sum=80*(long long)headphone + 10*(long long)shell + 8*(long long)protector;
        float ans=0.0f;
        if(sum<1000)
            ans=sum*0.1f;
        else if(sum>=1000 && sum<=1800)
            ans=100.0f+(sum-1000)*0.15f;
        else
            ans=(sum-1800.0)*0.2+220.0;
        return ans;
    }
    int main()
    {
        while(1)
        {
            int HP;//耳机
            int MPS;//手机壳
            int CSP;//手机贴膜 
            printf("请分别输入三种手机配件的销售情况(按耳机、手机壳、手机贴膜顺序,空格隔开):
    ");
            scanf("%d",&HP);
            scanf("%d",&MPS);
            scanf("%d",&CSP);
            float ans=commission(HP,MPS,CSP);
            if(fabs(ans+1.0f)<=0.000000001) 
            {
                printf("输入数量不满足要求
    
    ");
                continue;
            }
            else
                printf("佣金金额:%.2f元
    
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    计算机网络-TCP的三次握手与四次挥手
    计算机网络-XSS及CSRF攻击防御
    计算机网络-HTTP与HTTPS的区别
    装饰器模式和代理模式的区别
    23种设计模式总结
    单例模式详解
    常用设计模式总结
    PG-用户|角色管理
    PG-表空间管理
    TiDB-性能测试
  • 原文地址:https://www.cnblogs.com/ChainYugi/p/6530151.html
Copyright © 2020-2023  润新知