/*
After 141 year Cleo's interest over Daphne's.
Daphne's principle: 14200.
Cleo's principle: 97205.5.
*/
#include <iostream>
using namespace std;
int main() {
int countYear = 0;
const float principle = 100;
const float DaphneInterestPer = 0.1;
const float CleoInterestPer = 0.05;
float DaphnePrinciple = principle;
float CleoPrinciple = principle;
float DaphneSum = principle * DaphneInterestPer;
float CleoSum = principle * CleoInterestPer;
while (CleoSum <= DaphneSum) {
if (CleoSum == DaphneSum)
break;
DaphnePrinciple += principle;
CleoPrinciple = principle + CleoSum;
DaphneSum += DaphnePrinciple * DaphneInterestPer;
CleoSum += CleoPrinciple * CleoInterestPer;
countYear++;
}
cout << "After " << countYear << " year Cleo's interest over Daphne's.\n";
cout << "Daphne's principle: " << DaphnePrinciple << ".\n";
cout << "Cleo's principle: " << CleoPrinciple << ".\n";
return 0;
}
c++ primer plus 第五章《编程题5.9.4》
最新推荐文章于 2024-07-23 12:53:55 发布