#include<iostream>
using namespace std;
void main()
{
int count;
float n,expend;
cout<<"请输入购买书的数量:"<<endl;
cin>>count;
if(count%10==1)
{
n=count/10;
n=60*n;
expend=n+8;
}
if(count%10==2)
{
n=count/10;
n=60*n;
expend=n+15.2;
}
if(count%10==3)
{
n=count/10;
n=60*n;
expend=n+21.6;
}
if(count%10==4)
{
n=count/10;
n=60*n;
expend=n+25.6;
}
if(count%10==5)
{
n=count/10;
n=60*n;
expend=n+30;
}
if(count%10==6)
{
n=count/10;
n=60*n;
expend=n+38;
}
if(count%10==7)
{
n=count/10;
n=60*n;
expend=n+45.2;
}
if(count%10==8)
{
n=count/10;
n=60*n;
expend=n+51.2;
}
if(count%10==9)
{
n=count/10;
n=60*n;
expend=n+55.6;
}
if(count%10==0)
{
n=count/10;
n=60*n;
expend=n;
}
cout<<"需要付的钱为:"<<expend;
}



本次实验题目:
书店针对《哈利波特》系列书籍进行促销活动,一共5卷,用编号0、1、2、3、4表示,单独一卷售价8元, 具体折扣如下所示:
本数 折扣
2 5%
3 10%
4 20%
5 25%
根据购买的卷数以及本数,会对应不同折扣规则情况。单数一本书只会对应一个折扣规则,例如购买了两本卷1,一本卷2,则可以享受5%的折扣,另外一本卷一则不享受优惠。
设计算法能够计算出读者购买一批书的最低价格。
思路:
我的做法是,将所输入的书的数量,除以10之后余数分成十种情况讨论。例如:
6=5+1;7=5+2;8=4+4;最简等等。
所求得的商*10*80%+余数的情况,即可为解。
遇到的问题:编程过程中没遇到什么问题。