Topic:
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%
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. (Due date 2016-6-3 18:00)
Design ideas: By listing purchase 1~10 book The minimum cost is the purchase of the form, to find the corresponding law: 5 The following purchase different number of the most preferential, 6 (1,5) 7 (2,5) 8 (9) (4,5) 10 (5,5)
Code implementation:
Chen Chang 20143051// 2016.5.30 harry Potter promo book #include<iostream>using namespace std;void main () {double monery;int Num;int shang,yu;cout<< "Please enter purchase quantity:"; Cin>>num;if (num<=5) {switch (num) {case (1): Monery=8;break;case (2) : Monery=16*0.95;break;case (3): Monery=24*0.9;break;case (4): Monery=32*0.8;break;case (5): Monery=30;break;default: cout<< "Input Error!! "<<endl;}} else if (num<=10) {switch (num) {case (6): Monery=38;break;case (7): Monery=45.2;break;case (8): Monery=51.2;break; Case (9): Monery=55.6;break;case (Ten): Monery=60;break;}} Else{shang = Num/10;yu = num% 10;switch (yu) {case (1): Monery=8;break;case (2): Monery=16*0.95;break;case (3): monery=24*0 .9;break;case (4): Monery=32*0.8;break;case (5): Monery=30;break;case (6): Monery=38;break;case (7): Monery=45.2;break ; case (8): Monery=51.2;break;case (9): Monery=55.6;break;} Monery +=60*shang;} cout<< "Purchase Quantity:" <<num<< " Payable Amount:" <<monery<<endl;}
Realize:
Personal Summary:
List the possibilities and find the relevant rules
Classroom Exercises-promotional books