Promotion of book Promotions

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

Through the analysis of this topic, find out the law for the remainder of the problem, we can first find 5,6,7,8,9 four group of the best plan, the rest of the data Mod5 plus 5, but also 5,6,7,8,9 these situations, you can get the best solution.

Third, the Code

1#include"stdio.h"2 intMain ()3 {4     intBnum,num,num1,jixu;5     DoubleMoney ;6a1:printf ("Please enter the number of books:");7scanf"%d",&bnum);8num1=bnum/5-1;9num=bnum%5+5;Ten     Switch(num) One     { A      Case 5: -money=5*8*0.75; -          Break; the      Case 6: -money=5*8*0.75+8; -          Break; -      Case 7: +money=5*8*0.75+2*8*0.95; -          Break; +      Case 8: Amoney=4*8*0.8*2; at          Break; -      Case 9: -money=5*8*0.75+4*8*0.8; -          Break; -     } -Money=money+num1*5*8*0.75; inprintf"The Total price of the book you purchased:%g\n", money); -printf"do you want to continue? Continue please enter 1, exit input 0\n"); toscanf"%d",&Jixu); +     Switch(Jixu) -     { the      Case 0: *printf"Welcome to use next time! \ n"); $          Break;Panax Notoginseng      Case 1: -         GotoA1; the          Break; +     } A     return 0; the}
View Code

Four, the experiment

Five, experimental experience

A lot of problems, we want to find the law, especially the infinite problem, and we have to think about in the design, such as before I did not design loop input link, each use must reopen, very unfriendly.

Promotion of book Promotions

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.