1. Title.
The bookstore for the Harry Potter series of books for promotional activities, a total of 5 volumes, with numbers 0, 1, 2, 3, 4, said,
A single reel is priced at $8, and the specific discount is as follows:
Discount on this number
2 5%
3 10%
4 20%
5 25%
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, if you purchase two volumes of Volume 1, one volume 2, you can enjoy a 5% discount, and 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.
Because in addition to buy 8 copies, regardless of how many buy, should be the maximum discount of 5 of this calculation, in order to make the purchase of this batch of books the lowest price.
3. Code.
#include <iostream.h>intMain () {intK,m,n; Doublesum=0; cout<<"The bookstore for the Harry Potter series of books for promotional activities, a total of 5 volumes, with numbers 0, 1, 2, 3, 4, said,"<<Endl; cout<<"A single reel is priced at $8, and the specific discount is as follows:"<<Endl; cout<<"discount on this number"<<Endl; cout<<"2 5%"<<Endl; cout<<"3 10%"<<Endl; cout<<"4 20%"<<Endl; cout<<"5 25%"<<Endl; cout<<Endl; cout<<"Please enter the number of books the reader wants to buy:"<<Endl; CIN>>K; M=k/5; N=k%5; if(k!=8) { Switch(n) { Case 0: Sum=m* +*0.75; Break; Case 1: Sum=m* +*0.75+8; Break; Case 2: Sum=m* +*0.75+ -*0.95; Break; Case 3: Sum=m* +*0.75+ -*0.9; Break; Case 4: Sum=m* +*0.75+ +*0.8; Break; } } Elsesum=2*4*8*0.8; cout<<"the lowest price the reader buys for a batch of books is:"<<Endl; cout<<sum<<"Yuan"<<Endl; return 0;}
4. Run the results.
5. Summary of the experiment.
Some of the problems are regular, as long as the rule can be a very simple algorithm to achieve a feeling very complex problem.
Classroom Practice-The calculation method calculates the lowest price that a reader buys a batch of books.