Money-changing games between rich people and strangers

Source: Internet
Author: User

[Cpp]
Computer content: Money-changing games between rich people and strangers
 
Objective: To switch money between a rich man and a stranger
* Copyright (c) 2012, computer College, Yantai University
* All rights reserved.
* Author: Li Meng
* Completion date: January 1, November 2, 2012
* Version No.: v1.0
*
* Input Description: None
 

* Problem description: A millionaire encounters a stranger who talks to him about a money exchange plan,
The plan is as follows: I will pay you 100,000 yuan a day, and you only need to pay me a cent on the first day,
The next day I still give you 100,000 yuan, you give me two cents, the third day I still give you 100,000 yuan,
You give me four cents,... the money you give me every day is twice the money of the previous day until the full month (30 days ),
The millionaire was very happy to accept the contract. Compile the program,
This money exchange plan is a cost-effective deal for a millionaire.
* Program output: outputs the daily payment change and the final result after 30 days.
*/
# Include <iostream>
Using namespace std;
Int main ()
{
Double m1 = 100000, m2 = 0.01, t = 1, sum1 = 0, sum2 = 0, sum3, sum4;
For (; t <= 30; m2 = 2 * m2, t ++)
{
Cout <"day" <t <"day" <endl;
Cout <"stranger to Rich Man" <m1 <"Yuan" <endl;
Cout <"Rich to strangers" <m2 <"Yuan" <endl;
Cout <"earning money on the day" <M1-M2 <"Yuan" <endl;
Cout <endl;
Sum1 = sum1 + m1;
Sum2 = sum2 + m2;
}
Cout <endl;
Cout <"strangers give monopoly" <sum1 <"Yuan" <endl;
Cout <"a rich man gives a total of strangers" <sum2 <"Yuan" <endl;
If (sum1> sum2 ){
Samsung = sum1-sum2;
Cout <"Rich earned" <sum3 <"Yuan" <endl ;}
Else {
Sum4 = sum2-sum1;
Cout <"Strangers make money" <sum4 <"Yuan" <endl;
Cout <endl ;}
Return 0;
}

Output result:
Experience :!!!

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.