Drink soda, 1 bottles of soda 1 yuan, 2 empty bottles can be replaced by a bottle of soda, to 20 yuan, can be how much soda.

Source: Internet
Author: User

#include <stdio.h>
#include <windows.h>
int s (int t)
{
int z = 0;
int h = 0;
int sum = t;

while (t>1)
{if (t%2==0)
{
SUM=SUM+T/2;
T=T/2;
}
else if (t%2==1)
{
SUM=SUM+T/2;
T=T/2;
h++;
if (h==2)
{sum++;
h=0;
}

}
}
if (h==1&&t==1)
{sum++;}
printf ("The number of drinks you can buy is%d\n", sum);
}
int main ()
{int k = 0;
int money = 0;
printf ("Please input the amount of money \ n");
do{
scanf ("%d", &k);
if (k<0)
{
printf ("Input not valid, please re-enter \ n");


}
}while (k<0);

Money = s (k);




System ("pause");
return 0;
}

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.