Best deals on book purchases

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, design ideas
Find out how to get the most out of your purchase by buying a discount of the different ways to buy 5 to 10 books.
6 Book: (1) 1+5:5*8*0.25=10 7 book: (1) 2+5:2*8*0.05+5*8*0.25=10.8
(2) 2+4:2*8*0.05+4*8*0.2=7.2 (2) 3+4:3*8*0.1+4*8*0.2=6.64
(3) 3+3:3*8*0.1*2=4.8
8 Book: (1) 3+5:3*8*0.1+5*8*0.25=12.4 9 Book: (1) 4+5:4*8*0.2+5*8*0.25=16.4
(2) 4+4:4*8*0.2*2= 12.8
According to the above formula can be calculated to be able to make up 5 books when the lowest discount (in addition to purchase 8), when the purchase number of 8, the use of 4+4 purchase method can be the maximum discount.

Third, the program code

1#include <iostream.h>2#include <conio.h>3 #defineP 84 intMain ()5 {6     intnum;7     DoubleMoney ;8     intShang,yu;9     intJixu;Tencout<<"Please enter the number of books to buy:"<<Endl; OneCin>>num; Ashang=num/5; -yu=num%5;  -     if(num==3) the     { -money=3*p*0.9; -     } -     Else +     { -money=shang*5*p*0.75; +         Switch(Yu) A         {  at          Case 0: Money=money; Break; -          Case 1: money=money+8; Break; -          Case 2: money=money+2*p*0.95; Break; -          Case 4: money=money+4*p*0.8; Break; -         } -         if(yu==3) in         { -Money= (shang-1)*5*p*0.75+4*8*0.8*2; to         } +     } -cout<<"minimum required RMB is"<<money<<"Yuan"<<Endl; thecout<<"whether to continue executing the program: (1, continue 0, exit)"<<Endl; *Cin>>Jixu; $     if(jixu==1)Panax Notoginseng     { -cout<<Endl; the main (); +     } A     Else the     { +         return 0; -     } $ getch (); $     return 0; -}

Four, the experimental summary
The experiment is relatively simple, with the teachers to provide attention in class, coupled with the accumulation of several previous experiments, soon completed the experimental content. Conclusion: you are accumulating.

Best deals 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.