UT源码105032014108

#include<stdio.h>

#define HP_PRICE 80
#define MPS_PRICE 10
#define CSP_PRICE 8 


float commission(int headphone,int shell,int protector){
    int sum=headphone*HP_PRICE+shell*MPS_PRICE+protector*CSP_PRICE; //计算销售额
    float com=0;
    if(sum<1000){  //销售额小于1000
        com=sum*0.1;
    }
    else if(sum>=1000&&sum<=1800){ //销售额大于1000小于1800
        com=(sum-1000)*0.15+100;
    }
    else{
        com=(sum-1800)*0.2+100+120; //销售额大于1800
    }
    return com;
}


void main(){
    int headphone,shell,protector;
    float com;

    while (1){
        printf("请输入耳机销售量:");
        scanf("%d",&headphone);
        printf("请输入手机保护膜销售量:");
        scanf("%d",&protector);
        printf("请输入手机保护壳销售量:");
        scanf("%d",&shell);
        if((headphone<0&&headphone!=-1)||shell<0||protector<0){ //收入不合法
            printf("输入数量不满足要求,请重新输入!\n");
        }
        else if(headphone==-1){    //退出
            printf("退出\n");
            break;
        }
        else{
            com=commission(headphone,shell,protector); //计算销售额
            printf("佣金为%.2f元\n",com);
        }
    }
    
}

 

posted @ 2017-03-10 16:48  Why-Not  阅读(249)  评论(0编辑  收藏  举报