(3)设计佣金问题的程序
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)
{
int sum=80*headphone + 10*shell + 8*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=100.0f+120.0f+(sum-1800)*0.2f;
return ans;
}
int main()
{
while(1)
{
double HP;//耳机
double MPS;//手机壳
double CSP;//手机贴膜
printf("请分别输入三种手机配件的销售情况(按耳机、手机壳、手机贴膜顺序,空格隔开):\n");
scanf("%lf",&HP);
scanf("%lf",&MPS);
scanf("%lf",&CSP);
double eps=0.000000001;
if(fabs(HP-(int)HP)<eps && fabs(MPS-(int)MPS)<eps && fabs(MPS-(int)MPS)<eps)
{
int hp=(int)HP;
int mps=(int)MPS;
int csp=(int)CSP;
if(-1==hp)
{
printf("程序结束");
break;
}
else if(hp<0 || mps<0 || csp<0)
{
printf("输入数量不满足要求\n");
continue;
}
else
printf("佣金金额:%.2lf元\n\n",commission(hp,mps,csp));
}
else
{
printf("输入数量不满足要求\n");
}
}
return 0;
原文:http://www.cnblogs.com/lkx1995/p/6532907.html