Software Engineering--Buy book Discount problem

Source: Internet
Author: User

1. Topics

The bookstore for the Harry Potter series of Books for the promotion of a total of 5 volumes, with numbers 0, 1, 2, 3, 4, a single volume of eight Yuan, the specific discount is as follows:

Book Discount

2 5%

3 10%

4 15%

5 20%

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. Design Ideas

A total of three scenarios can be considered according to the topic:

(1) Within five, this situation is not the same as buying, you can enjoy the best discount

(2) Six to nine, respectively calculate the corresponding optimal results

(3) 10 or more, such cases can be regulated to six to nine of the situation

3. Source code

#include <iostream.h>void main () {int num;int a,b;cout<< "Please enter the number of books to buy:";cin>>num;    A=num/5;b=num%5;if (b!=3) {cout<< "should buy" <<a<< "set of 5, plus" <<b<< "This is not the same, total" <<num< < "book" <<ENDL;} else{cout<< "should buy" <<a-1<< "set of 5, plus two sets of 4 different, a total of" <<num<< "book" <<endl;} cout<< "So you can enjoy the most discounts! "<<endl;}

4. Results

Software Engineering--Buy book Discount problem

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.