根据销售业绩计算提成-C++语言

来源:互联网 发布:莫尼卡·莱文斯基 知乎 编辑:程序博客网 时间:2024/04/30 00:07

题目为:提成的比例与销售的业绩相关,销售业绩小于等于10万时,比例为0.1,大于10万小于等于20万时,小于10万的部分提成0.1,大于10万的部分提成0.075,大于20万小于等于40万时,大于20万的部分提成0.05,大于40万小于等于60万时,大于40万的部分提成0.03,大于60万小于等于100万时,大于60万的部分提成0.015,大于100万时,大于100万的部分提成0.01。

下面是我的实现, 希望大家给点意见:

#include <iostream>using namespace std;const float profitTab[] = {0.0, 10.0, 20.0, 40.0, 60.0, 100.0};const float percentTab[] = {0.1, 0.075, 0.05, 0.03, 0.015, 0.01};float get_salary(float profit){    int i;    float salary = 0.0;    //float profit = 11;    for (i = 0; i < 5 && profit > profitTab[i + 1]; i++)    {        salary += percentTab[i] * (profitTab[i + 1] - profitTab[i]);    }    salary += percentTab[i] * (profit - profitTab[i]);    return salary;}int main(void){    float profit;    do    {        cout << "please input your profit in 10, 000 yuan:";        cin >> profit;        cout << get_salary(profit) << endl;    }while (profit >= 0);    return 0;}


原创粉丝点击