#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;
int main()
{
int number, i, everage_money;
double total_money, money, min = 0.01;
srand(time(0));
cout << "Please enter the number of the lucky money: ";
cin >> number;
cout << "Please enter the total money in the lucky money: $";
cin >> total_money;
for (i = 0; i < number - 1; i++)
{
everage_money = ((total_money - (number - i) * min) / (number - i)) * 100;
money = (1 + rand() % everage_money) / 100.0;
cout << "The #" << i + 1 << " has money: $" << setiosflags(ios::fixed) << setprecision(2) << money<< endl;
total_money = total_money - money;
}
cout << "The #" << i + 1 << " has money: $" << setiosflags(ios::fixed) << setprecision(2) << total_money << endl;
cin.get();
cin.get();
return 0;
}
本代码由carlzj原创,版权归carlzj所有,请勿抄袭,转载请注明出处,谢谢。
VS源码下载链接:http://download.csdn.net/detail/carlzj/8499717
更多内容,欢迎进入我的个人博客:Carl 张的小窝