First, the idea
There are 10 options for buying a book, each of which is considered separately. So you just need to consider the situation.
Second, the Code
//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%//letter 1301-1 Huangshan into 20133048#include <iostream>using namespacestd;voidBook_strategy (intN) { intoption; Option=n%Ten;//There are a total of 10 ways to buy books Doublevolume=n/5;//volume of books purchased intother_books=n%5;//The number of books remaining DoubleMoney ; Switch(option) { Case 0: money= +*volume*0.75; Break; Case 1: money= +*volume*0.75+8; Break; Case 2: money= +*volume*0.75+8*2*0.95; Break; Case 3: money= +*volume*0.75+8*3*0.9; Break; Case 4: money= +*volume*0.75+8*4*0.8; Break; Case 5: money= +*volume*0.75; Break; Case 6: money= +*volume*0.75+8; Break; Case 7: money= +*volume*0.75+8*2*0.95; Break; Case 8: money= +* (volume-1)*0.75+8*4*0.8*2; Break; Case 9: money= +*volume*0.75+8*4*0.8; Break; } if(option!=8) {cout<<"Purchase Proposal:"<<volume<<"set of book"<<"and the"<<other_Books<<"Volume book"<<Endl; } Else{cout<<"Purchase Proposal:"<<volume-1<<"set of book"<<"and two sets of 4-volume books"<<Endl; } cout<<"prices are:"<<money<<"Yuan";}voidMain () {Doublem; cout<<"Enter the number of books purchased:"; CIN>>m; while(m<0|| (M!= (int) (m)) {cout<<"the number of books is wrong, please re-enter"; CIN>>m; } cout<<"buy"<<m<<"of this book"; Book_strategy (m); }
Three
Iv. Summary
The root of this problem is to find out the law, if not found the law is difficult to complete.
Book Purchase Plan