@xBroken115
I don't know why you insist that a given day's savings is the previous day's savings times three. That's not what the instructions say.
The instructions say that he starts by donating one penny on the first day, and on every subsequent day he doubles the amount he donates.
On day# 1, he donates $0.01. His current, accumulated savings is $0.01.
On day# 2, he donates $0.02. His current, accumulated savings is $0.03 (0.01 + 0.02).
On day# 3, he donates $0.04. His current, accumulated savings is $0.07 (0.03 + 0.04).
On day# 4, he donates $0.08. His current, accumulated savings is $0.15 (0.07 + 0.08).
On day# 5, he donates $0.16. His current, accumulated savings is $0.31 (0.15 + 0.16).
And so on...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
int main() {
const int num_days = 15;
double donation_per_day = 0.01;
double total_savings = 0.0;
for (int i = 0; i < num_days; ++i) {
total_savings += donation_per_day;
std::cout << "Savings for Day# " << i + 1 << ":\t$" << total_savings << std::endl;
donation_per_day *= 2;
}
return 0;
}
|