Classroom Practice-The calculation method calculates the lowest price that a reader buys a batch of books.

Source: Internet
Author: User

1. Title.

The bookstore for the Harry Potter series of books for promotional activities, a total of 5 volumes, with numbers 0, 1, 2, 3, 4, said,

A single reel is priced at $8, and 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, if you purchase two volumes of Volume 1, one volume 2, you can enjoy a 5% discount, and another volume does not enjoy the discount.
The design algorithm calculates the lowest price for the reader to buy a batch of books.

2. Design ideas.

Because in addition to buy 8 copies, regardless of how many buy, should be the maximum discount of 5 of this calculation, in order to make the purchase of this batch of books the lowest price.

3. Code.

#include <iostream.h>intMain () {intK,m,n; Doublesum=0; cout<<"The bookstore for the Harry Potter series of books for promotional activities, a total of 5 volumes, with numbers 0, 1, 2, 3, 4, said,"<<Endl; cout<<"A single reel is priced at $8, and the specific discount is as follows:"<<Endl; cout<<"discount on this number"<<Endl; cout<<"2 5%"<<Endl; cout<<"3 10%"<<Endl; cout<<"4 20%"<<Endl; cout<<"5 25%"<<Endl; cout<<Endl; cout<<"Please enter the number of books the reader wants to buy:"<<Endl; CIN>>K; M=k/5; N=k%5; if(k!=8)    {        Switch(n) { Case 0: Sum=m* +*0.75;  Break;  Case 1: Sum=m* +*0.75+8;  Break;  Case 2: Sum=m* +*0.75+ -*0.95;  Break;  Case 3: Sum=m* +*0.75+ -*0.9;  Break;  Case 4: Sum=m* +*0.75+ +*0.8;  Break; }    }        Elsesum=2*4*8*0.8; cout<<"the lowest price the reader buys for a batch of books is:"<<Endl; cout<<sum<<"Yuan"<<Endl; return 0;}

4. Run the results.

5. Summary of the experiment.

Some of the problems are regular, as long as the rule can be a very simple algorithm to achieve a feeling very complex problem.

Classroom Practice-The calculation method calculates the lowest price that a reader buys a batch of books.

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.