码迷,mamicode.com
首页 > 其他好文 > 详细

课堂作业:书

时间:2016-06-02 21:42:55      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:

#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的折扣

课堂作业:书

标签:

原文地址:http://www.cnblogs.com/love-xi/p/5554201.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!