Bookstore Promotional Offers

Source: Internet
Author: User

First, the 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.

Second, the design idea

The topic is not difficult, some like elementary school maths problem. First of all to calculate a special situation, when buying 6,7,8,9 book, need to calculate the minimum cost of these conditions, the results that, in addition to 8, other cases are 5 cheap, buy 8, 4, 4 points more cost-effective. So 8 is a special place. The general rule is that the number of books divided by 5, you can draw the remainder, and then get the remainder and cost of the relationship, just a switch function on the line.

Third, the Code

#include <iostream.h>int main () {double sum;sum=1;int num,m;cout<< "Please enter purchase Quantity"; cin>>num;m=num%5;m=m+ 5;switch (m) {case 5:            sum=num*8*0.75;            break;        Case 6:            sum= (num-1) *8*0.75+8;            break;        Case 7:            sum= (num-2) *8*0.75+8*2*0.95;            break;        Case 8:            sum= (num-8) *8*0.75+4*8*0.8*2;            break;        Case 9:            sum= (num-4) *8*0.75+8*4*0.8;                break;        } cout<< "Best Rates" <<SUM<<ENDL;}

Four, the experiment

V. Summary of the Experiment

Due to previous neglect, the program output is not correct due to 8 of cases, and all the remainder of three. Later, after the improvement, the results of redundancy and 5 added, the problem solved. In summary, it turns all three cases into 8.

, so that the 8 can be divided into 4.4 completely unified together.

Experience summary, encounter problems, especially similar mathematical problems, first algebra calculation, pass the procedure, then summarize the errors, to arrive at a consistent conclusion and law.

Bookstore Promotional Offers

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.