您的位置:首页 > 其它

软件工程课堂练习购买图书

2016-05-30 17:55 239 查看


购书数量对10取余,每10本优惠的最大价钱都相同,然后再加之前以10为周期的优惠价钱,就可以算出总的优惠价格。

代码:

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
const float discount[10] = {0,0,0.1,0.3,0.8,1.25,1.25,1.35,1.6,2.05};
int count;
cout << "输入购书数量:";
cin >> count;
if (count < 0)
{
cout << "Error ! Illegal Input" << endl;
exit(1);
}
float result = (count / 10)* 2.5 + discount[count % 10];
cout << "优惠" <<setiosflags(ios::fixed)<<setprecision(2)<< 8 * result << endl;
}


运行截图

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: