Discounts on book Purchases

Source: Internet
Author: User

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.

Design ideas:

A group of books at the lowest price, a book discount, the average book discount maximum

The maximum discount for a single book is 25% (5 this set)

When the number of books cannot be a full multiple of 5:

1~4, enjoy the maximum discount on a given discount;

6~9, calculated by:

6 This is divided into 5+1 this purchase discount maximum;

7 This is divided into 5+2 this purchase discount maximum;

8 This is divided into 4+4 this purchase discount maximum;

9 This is divided into 5+4 this purchase discount maximum;

When the number is above 10,

Code:

1 //2-5% 3-10% 4-20% 5-25% 6-(5+1) 7-(5+2) 8-(4+4) 9-(5+4)2#include <iostream>3 using namespacestd;4 intMain ()5 {6     intnumbook=0;7     DoubleSummonny =0;8cout <<"How many books do you buy altogether? "<< Endl <<"This number:";9CIN >>Numbook;TenSummonny + = (Numbook/Ten* -); One     Switch(numbook%Ten) A     { -      Case 0: Break; -      Case 1: Summonny + =8; Break; the      Case 2: Summonny + =15.2; Break; -      Case 3: Summonny + =21.6; Break; -      Case 4: Summonny + =25.6; Break; -      Case 5: Summonny + = -; Break; +      Case 6: Summonny + = -; Break; -      Case 7: Summonny + =45.2; Break; +      Case 8: Summonny + =51.2; Break; A      Case 9: Summonny + =55.6; Break; at     default: -          Break; -     } -cout <<"Total"<< Summonny <<"Yuan. "<<Endl; -     return 0; -}
View Code

Discounts on book Purchases

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.