Classroom Exercise: Buying Promotional book questions

Source: Internet
Author: User

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: this number         & nbsp;         Discount                                      2                        5%                                     3                        10%                                     4                        20%                                     5                        25 %1 will correspond to different discount rules depending on the number of volumes purchased and this number. 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 2 design algorithm calculates the lowest price for the reader to buy a batch of books. 3 requires the design idea, code implementation, implementation, personal summary in the form of blog post.   Design ideas   According to the discount and the number of books can know: When buying more than 10 books, will be the number of surplus, calculated when buying 6, 7, 8, 9 book The minimum price, the rest can be divisible by 5 directly with the purchase of 5 sets of discount price is the best solution.   Source Code
#include <iostream>using namespace std;float pricelowest;void f (int booknum) {int N; N=booknum%5;switch (N) {case 0:pricelowest=booknum*8*0.75;break;case 1:pricelowest= (booknum-n) *8*0.75+8;break;case 2:pricelowest= (booknum-n) *8*0.75+2*8*0.95;break;case 3:pricelowest= (booknum-n) *8*0.75+4*8*0.8*2-5*8*0.75;if ( booknum<5) {pricelowest+=0.4;} Break;case 4:pricelowest= (booknum-n) *8*0.75+4*8*0.8;break;default:cout<< "Error!" <<endl;}} void Main () {int Q=0;while (q==0) {int booknum;cout<< "Please enter purchase quantity:"; Cin>>booknum;f (booknum);cout<< " The lowest price is: "<<priceLowest<<endl;cout<<" Do you want to continue testing? (enter 0 to continue) "; cin>>q;}}

  

Program

Experimental summary

The main problem of this experiment is to buy 6-9 books and buy 11-14 books whether the%5 redundancy problem, solve this problem can basically write a less complex algorithm to

Classroom Exercise: Buying Promotional book questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.