程序代码如下:
#include "stdafx.h"
#include
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
double daphne = 100.0;
double cleo = 100.0;
const double rate_1 = 0.1;
const double rate_2 = 0.05;
double year = 0;
double temp = cleo - daphne;
while (temp <= 0)
{
year++;
daphne = daphne + daphne*rate_1*year;
double k = pow(1 + rate_1, year);
cleo = cleo*k;
temp = cleo - daphne;
}
cout << "after " << year << " years, cleo has more money than daphne! " << endl;
cout << "the money of daphne is: " << daphne << endl;
cout << "the money of cleo is: " << cleo << endl;
return 0;
}
求解答!!谢谢大神