First, the 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. Second, the design of the idea of the course is the time to have a train of thought, the class went to Baidu a little bit of this problem and then found that the teacher to recommend the book as if it is called programming beauty of the classic example, originally wanted to see the idea of the great God, but the more you see the more do not understand. Can only say that the programmer brother of the language base of a force, so simply or according to my own ideas, is to buy the book of the book divided by 5 for the remainder plus 5, and then will get 6789 of these four numbers, in order to calculate how much you need to arrange the most cost-effective plus the rest of the book must be 5 multiples, Well, forget the rest. That's how NN came. Third, the Code
1#include <iostream.h>2 intMain ()3 {4 inta,b,c;5 floath1,h2,h3,sum1,sum2,sum;6cout<<"Enter the number of the numbers you want to buy:";7Cin>>A;8b=a%5+5;9c=a/5-1;Tensum1=c*8; One if(a%5==0) A { -sum=a/5*8*0.8; - } the Else - { - Switch(b) - { + Case 6: -h1=3*8*0.9*2; +H2=4*8*0.8+2*8*0.95; Ah3=5*8*0.75+8; at if(h1>H2) - { -h1=H2; - } - if(h1>h3) - { inh1=H3; - } to Break; + Case 7: -h1=5*8*0.75+2*8*0.95; theH2=4*8*0.8+3*8*0.9; * if(h1>H2) $ {Panax Notoginsengh1=H2; - } the Break; + Case 8: Ah1=4*8*0.8*2; theH2=5*8*0.75+3*8*0.9; + if(h1>H2) - { $h1=H2; $ } - Break; - Case 9: theh1=5*8*0.75+4*8*0.8; - Break;Wuyi } theSum2=H1; -sum=sum1+sum2; Wu } -cout<<sum<<Endl; About return 0; $}
Iv. Results of operation
See, everybody's using it. Buy eight books I also buy eight books ~ ~ ~
V. Summary of the EXPERIENCE
This is a smooth, although every time writing code just know thought, but never write, but this time really is I wrote, although asked classmates a lot of low-level problems, but I feel good. After all, it's done. Well, that's it, I'm going to go ahead and write my next blog post. The DA.
The book discount problem in Software engineering class practice