[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 :!!!