About the purchase of the Harry Potter book

Source: Internet
Author: User

Design ideas:

  

Through the calculation found that the purchase just press (x*5+y) (0<y<5), X set of 5 in addition to buy Y (0<y<5) the lowest price, but there is a column outside, in the case of x*5+2*4 this, according to X set of 5, 2 sets of 4 this purchase than x sets of 5 this separately buy y cheaper. So it can be programmed by situation analysis.

Program code:  

1#include <iostream>2 using namespacestd;3 4 voidMain ()5 {6     intx;7cout <<"Please enter the number you want to buy:"<<Endl;8CIN >>x;9 Ten     inti; Onei = x/5; A  -     if(X <5) -     { the         Switch(x) -         { -          Case 1: -cout <<"Buy 1 book The lowest price is 8 yuan"<<Endl; +              Break; -          Case 2: +cout <<"Buy 2 book the lowest price for"<< x*8*0.95<<"Yuan"<<Endl; A              Break; at          Case 3: -cout <<"Buy 3 book the lowest price for"<< x*8*0.9<<"Yuan"<<Endl; -              Break; -          Case 4: -cout <<"Buy 4 book the lowest price for"<< x*8*0.8<<"Yuan"<<Endl; -         } in     } -     Else{ to         Switch(%5) +         { -          Case 0: thecout <<"buy"<< I <<"set of 5 copies of the"<<Endl; *cout <<"the lowest price is:"<< i*8*5*0.75<<Endl; $              Break;Panax Notoginseng          Case 1: -cout <<"buy"<< I <<"set of 5 copies of the"<<Endl; thecout <<"Plus"<< x%5<<"this"<<Endl; +cout <<"the lowest price is:"<< i*8*5*0.75+ (Percent5)*8<<Endl; A              Break; the          Case 2: +cout <<"buy"<< I <<"set of 5 copies of the"<<Endl; -cout <<"Plus"<< x%5<<"this"<<Endl; $cout <<"the lowest price is:"<< i*8*5*0.75+ (Percent5)*8*0.95<<Endl; $              Break; -          Case 3: -cout <<"buy"<< I-1<<"set of 5 copies of the"<<Endl; thecout <<"plus 2 sets of 4 copies ."<<Endl; -cout <<"the lowest price is:"<< (I-1)*8*5*0.75+2*4*8*0.8<<Endl;Wuyi              Break; the          Case 4: -cout <<"buy"<< I <<"set of 5 copies of the"<<Endl; Wucout <<"Plus"<< x%5<<"this"<<Endl; -cout <<"the lowest price is:"<< i*8*5*0.75+ (Percent5)*8*0.8<<Endl; About         } $     } -}

Results:

Personal Summary:

  The problem is quite simple, but how to make it easier is the best. Through analysis, this method was finally selected. It feels so simple.

About the purchase of the Harry Potter book

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.