Classroom Homework--book Best purchase

Source: Internet
Author: User

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

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.