Drinking beer.

Source: Internet
Author: User

A beer on the market, 2 yuan per bottle, 4 caps can be exchanged for a bottle of beers, two empty beer can also be exchanged for a bottle of beer. How many bottles can I drink when I finish entering money?

1#include <stdio.h>2 3 voidMain ()4 {5      intMoney,bottle_top,empty_bottle0,empty_bottle;6      intbottle=0;//prevent non-normal output7 8printf"Please enter the amount of money : \ n");9scanf"%d",&Money );Ten      if(money<2) Oneprintf"your money will not buy goods!\n"); A      Else -bottle=money/2; -bottle_top=money/2; theempty_bottle=money/2; -       while((empty_bottle>=2)|| (bottle_top>=4))//change "wine bottle", then "wine cap" -      { -                                        +bottle=bottle+empty_bottle/2;//Beer bottles for beer caps, beer bottles-"beers-" beer caps + beer bottles, the maximum number of beer can be exchanged -bottle_top=bottle_top+empty_bottle/2;//bottle of wine bottles to produce beer cover number plus the original number of beer cover +Empty_bottle=empty_bottle%2+empty_bottle/2;//Bottle number of bottles and the number of beer bottles that have been left. A  atbottle=bottle+bottle_top/4;//Beer cover for beer bottle, beer lid-beer-beer bottle + beer lid, can redeem maximum number of beer -empty_bottle=empty_bottle+bottle_top/4;//bottle of wine cover for the number of beer bottles plus the original number of beer bottles left -bottle_top=bottle_top%4+bottle_top/4;//bottles of wine cover converted to produce beer cover number plus the original remaining number of beer machine cover -           -      } -printf"You can drink%d bottles of beer!", bottle); inprintf"number of empty bottles left for redemption:%d!\n", empty_bottle); -printf"number of empty caps left for redemption:%d!\n", bottle_top); to}

Printing results:

Please enter the amount of money: 8 You can drink 11 bottles of beer ! The number of empty bottles left for redemption:1! number of empty caps for redemption: 3!  Continue

Drinking beer.

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.