Buying "Harry Potter" books questions

Source: Internet
Author: User

First, the topic requirements

Bookstore for the "Harry Potter" series of books promotional activities, a total of 5 volumes, with numbers 0, 1, 2, 3, 4, a single volume of 8 yuan, specific preferential information as follows:

Discount on this number

2 5%

3 10%

4 20%

5 25%

Depending on the number of volumes purchased, the program is able to purchase a batch of books at its lowest price, with the corresponding offers.

Second, design ideas

Existing five books in the offer, already in detail in the table, buy 6 to 9 books, if five of them enjoy 25% discount, we left the table to find the corresponding preferential information, that is, there is a combination of forms, so that the price of the book to buy the lowest.

Third, the Code

1#include <iostream.h>2 voidMain ()3 {4     intNum//this number5     intRecord//Business6     intremainder;//remainder7     DoublePrice ;8     intn=1;9      while(n)Ten     { Onecout<<"Please enter the number of books you buy:"<<Endl; ACin>>num; -record=num/5; -remainder=num%5; the         if(record>=2) -         {  -record--; -remainder=remainder+5; +         } -         if(num<=5) +         { A             Switch(num) at             { -              Case 0: -Price=0; -                  Break; -              Case 1: -Price=8; in                  Break; -              Case 2: toPrice= -*(1-0.05); +                  Break; -              Case 3: thePrice= -*(1-0.1); *                  Break; $              Case 4:Panax NotoginsengPrice= +*(1-0.2); -                  Break; the              Case 5: +Price= +*(1-0.25); A                  Break; the             default: +                  Break; -             } $         } $         Else -         { -             Switch(remainder) the             { -              Case 5:Wuyiprice=record* +*(1-0.25)+ +*(1-0.25); the                  Break; -              Case 6: Wuprice=record* +*(1-0.25)+ +*(1-0.25)+8; -                  Break; About              Case 7: $price=record* +*(1-0.25)+ +*(1-0.2)+ -*(1-0.05); -                  Break; -              Case 8: -price=record* +*(1-0.25)+ +*(1-0.2)*2; A                  Break; +              Case 9: theprice=record* +*(1-0.25)+ +*(1-0.25)+ +*(1-0.2); -                  Break; $             default: the                  Break; the             } the         } thecout<<"buy"<<num<<"The lowest price of this book is:"<<price<<"Yuan"<<Endl; -cout<<"continue entering 1, exit input 0"<<Endl; inCin>>N; the     } the}

Iv. Results of operation

Buying "Harry Potter" books questions

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.