1. Topics
The bookstore for the Harry Potter series of Books for the promotion of a total of 5 volumes, with numbers 0, 1, 2, 3, 4, a single volume of eight Yuan, the specific discount is as follows:
Book Discount
2 5%
3 10%
4 15%
5 20%
Depending on the number of volumes purchased and this number, different discount rules will be applicable. The singular book only corresponds to one discount rule, for example, two volume 1, one volume 2, you can enjoy 5% discount, another volume does not enjoy the discount. The design algorithm calculates the lowest price for the reader to buy a batch of books.
2. Design Ideas
A total of three scenarios can be considered according to the topic:
(1) Within five, this situation is not the same as buying, you can enjoy the best discount
(2) Six to nine, respectively calculate the corresponding optimal results
(3) 10 or more, such cases can be regulated to six to nine of the situation
3. Source code
#include <iostream.h>void main () {int num;int a,b;cout<< "Please enter the number of books to buy:";cin>>num; A=num/5;b=num%5;if (b!=3) {cout<< "should buy" <<a<< "set of 5, plus" <<b<< "This is not the same, total" <<num< < "book" <<ENDL;} else{cout<< "should buy" <<a-1<< "set of 5, plus two sets of 4 different, a total of" <<num<< "book" <<endl;} cout<< "So you can enjoy the most discounts! "<<endl;}
4. Results
Software Engineering--Buy book Discount problem