课堂作业:书

#include <iostream>
using namespace std;
double p(int x)
{
    double pc;
    if (x == 1)
        pc = 8;
    else if (x == 2)
        pc = 16 * 0.95;
    else if (x == 3)
        pc = 24 * 0.9;
    else if (x == 4)
        pc = 32 * 0.8;
    else if (x == 5)
        pc = 40 * 0.75;
    return pc;

}
void main()
{
    int i, j = 0, num;
    double price = 0.00;
    cout << "请输入购买的本数" << endl;
    cin >> num;
    if (num <= 5)
    {
        price = p(num);
    }
    else if (num <= 10)
    {
        price = p(num / 2) + p(num - (num / 2));
    }
    else
    {
        i= num / 5-1;
        j= num % 5 + 5;
        price = i * 40 * 0.75 + p(j / 2) + p(j - (j / 2));
    }
    cout << "书的最少价格为" << price << endl;

}

 

设计思路:
 当书大于5本小于10本时,最少价格位本数/2和本数-本数/2的折扣

posted @ 2016-06-02 19:45  最佳BUG制作者  阅读(108)  评论(0编辑  收藏  举报