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

购买《哈利波特》书籍

时间:2015-05-13 21:36:52      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

我们完全可以在书的数量大于5时,直接除于5,得到余数,当数目可以变为x*5+2*4时,则购入X套与2套4本,这是极好的。。。。

 1 #include <iostream>
 2 using namespace std;
 3 
 4 void main()
 5 {
 6     int x;
 7     cout << "请输入要购买的本数:" << endl; 
 8     cin >> x;
 9 
10     int i;
11     i = x/5;
12 
13     if (x < 5)
14     {
15         switch(x)
16         {
17         case 1:
18             cout << "买1本书最低价格为8元"<< endl;
19             break;
20         case 2:
21             cout << "买2本书最低价格为" << x*8*0.95 << "元"<< endl;
22             break;
23         case 3:
24             cout << "买3本书最低价格为" << x*8*0.9 << "元"<< endl;
25             break;
26         case 4:
27             cout << "买4本书最低价格为" << x*8*0.8 << "元"<< endl;
28         }
29     }
30     else{
31         switch(x%5)
32         {
33         case 0:
34             cout << "买" << i << "套5本的" << endl;
35             cout << "最低价格为:" << i*8*5*0.75<< endl;
36             break;
37         case 1:
38             cout << "买" << i << "套5本的" << endl;
39             cout << "外加" << x%5 << "本" << endl;
40             cout << "最低价格为:" << i*8*5*0.75 + (x%5)*8<< endl;
41             break;
42         case 2:
43             cout << "买" << i << "套5本的" << endl;
44             cout << "外加" << x%5 << "本" << endl;
45             cout << "最低价格为:" << i*8*5*0.75 + (x%5)*8*0.95 << endl;
46             break;
47         case 3://特殊情况
48             cout << "买" << i-1 << "套5本的" << endl;
49             cout << "外加2套4本" << endl;
50             cout << "最低价格为:" << (i-1)*8*5*0.75 + 2*4*8*0.8 << endl;
51             break;
52         case 4:
53             cout << "买" << i << "套5本的" << endl;
54             cout << "外加" << x%5 << "本" << endl;
55             cout << "最低价格为:" << i*8*5*0.75 + (x%5)*8*0.8 << endl;
56         }
57     }
58 }
技术分享

购买《哈利波特》书籍

标签:

原文地址:http://www.cnblogs.com/chengchengshuaio/p/4501496.html

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