1. Topic Requirements
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. 2, the design idea only need to calculate clearly buy 6,7,8,9 this time, above 10 when the first 5 buy can, through the classroom calculation buy six, cent 5-1 buy the most preferential, buy 7, sub 5-2 buy the most preferential, buy 8 this time, cent 4-4 buy the most preferential, buy 9 This time, cent 5-4 buy the most preferential 3, design code
#include <iostream.h>intMain () {inti,j,k; Doublesum=0; cout<<"Please enter the number of books to buy"<<Endl; CIN>>i; J=i/5; K=i%5; if(k==0) {sum=j* -; } Else if(k==1) {sum=j* -+8; } Else if(k==2) {sum=j* -+ -*0.95; } Else if(k==3) {sum= (J-1)* -+ -*0.8; } Else if(k==4) {sum=j* -+ +*0.8; } cout<<"Best Available rate for:"<<sum<<Endl; return 0;}
4, Experimental results
5, experimental experience
Because of the purchase of a batch of books so 5 of the situation directly by discount to buy can, in fact, the topic looks more complicated actually, but because of the various numbers of book prices, so careful analysis of the very simple, there is this program is only applicable to the topic given the discount ~ ~
Classroom Homework--book Best purchase