UT源码+117(改)

设计佣金问题的程序

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 "stdafx.h"
#include "iostream"
using namespace std;
float  commission(int headphone, int shell, int protector)
{
    float paymoney;
    int total = headphone * 80 + shell * 10 + protector * 8;
     if (total < 1000)
    {
         paymoney = total*0.1;
         cout << "佣金为:" << paymoney;
    }
    else if (total >= 1000 && total <=1800)
    {
         paymoney = (total - 1000)*0.15 + 100;
         cout << "佣金为:" << paymoney;
    }
    else if (total>1800)
    {
         paymoney = (total - 1800)*0.2 + 220;
         cout << "佣金为:" << paymoney;
    }
    return paymoney;
}
bool check(char *str)//判断是否为数字字符
{
    int i;
    for (i = 0; i < strlen(str); i++)
    if (str[i] < '0' || str[i] > '9')
        return false;
    return true;
}
int change(char *str)//数字字符转为整形
{
    int len = strlen(str);
    int h = 0;
    for (int i = 0; i < len; i++)
    {
        str[i] = str[i] - '0';
    }
    for (int i = 0; i < len; i++)
    {
         h = h * 10 + str[i];
    }
    return h;
}
int _tmain(int argc, _TCHAR* argv[])
{
    char str1[30];
    char str2[30];
    char str3[30];
    int headphone, shell, protector;
    while(1)
    {
        cout << "请分别输入三种手机配件的销售情况:" << endl;
        cin >> str1 >> str2 >> str3;
        if (check(str1) && check(str2) && check(str3))
        {
            headphone = change(str1);
            shell = change(str2);
            protector = change(str3);
            commission(headphone, shell, protector);
        }
        else
        {
            cout << "输入数量不满足要求,返回重新输入";
        }
        system("pause");
    }
}

 

posted @ 2017-03-20 23:33  陈俊超  阅读(196)  评论(0编辑  收藏  举报