1. Design Topics
Bookstore for the "Harry Potter" series of books for promotional activities, a total of 5 volumes, with numbers 0, 1, 2, 3, 4, a single volume of 8 yuan, the specific discount is as follows:
Discount on this number
2 5%
3 10%
4 20%
5 25%
2. Design Requirements
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.
Requires the design idea, code implementation, implementation, personal summary in the form of blog post.
3. Design Ideas
Can be determined is the purchase quantity under 5, buy different volume book is the cheapest, more than 5 of the need in two cases, 6 5,1 distribution, 7 5,2 distribution, 8 copies of the allocation, 9, 5,4 allocation, 10, 5,5 assigned to the best.
4. Code
1#include <iostream>2 using namespacestd;3 intMain ()4 {5 intnum;6 intm;7 intn,d;8 Doublesum;9 Do{Tencout<<"Please enter the book to buy book:"; OneCin>>num; A - if(num<=0) - { thecout<<"Please re-enter the number of books to buy:"; - } - Else if(num>0) - { +m=num/5; -n=num%5; + if(m==0) A { at if(n==0) - { -sum=0; - } - Else if(n==1) - { insum=8; - } to Else if(n==2) + { -sum=8*2*(1-0.05); the } * Else if(n==3) $ {Panax Notoginsengsum=8*3*(1-0.10); - } the Else if(n==4) + { Asum=8*4*(1-0.20); the } + } - Else if(m>0) $ { $ if(n==0) - { -sum=5*m*8*(1-0.25); the } - Else if(n==1)Wuyi { thesum=5*8*m* (1-0.25)+8; - } Wu Else if(n==2) - { Aboutsum=5*8*m* (1-0.25)+8*2*(1-0.05); $ } - Else if(n==3) - { -sum=5*8* (M-1)*(1-0.25)+8*4*2*(1-0.20); A } + Else if(n==4) the { -sum=5*8*m* (1-0.25)+8*4*(1-0.20); $ } the } thecout<<"the lowest price is:"<<sum<<"Yuan"<<Endl; thecout<<"If you need to calculate the price of the other quantity please lose 1, otherwise 0:"; theCin>>D; -cout<<Endl;} in } the while(d==1); the return 0; About}
5. Procedure
6. Experimental Thoughts
The input statement is to be placed in front of the operation statement when the input variable is to be operated, otherwise it cannot run, which is the error encountered in this programming. I feel that this program can be used to do the function, the code may be easy to read a little, may be a few curly braces it.
Book Discount Issues