Answer:#include <iostream>
using namespace std;
int main()
{
const double RATE = 5;
const double INITIAL_BALANCE = 10000;
const double TARGET = 2 * INITIAL_BALANCE;
cout << "Annual contribution: " << endl;
double contribution;
cin >> contribution;
double balance = INITIAL_BALANCE;
int year = 0;
// Add annual contribution, but not in year 0
while (balance < TARGET){
year++;
balance = balance * (1 + RATE/100) + contribution;
}
balance = balance - contribution;
cout << "Year: " << year << endl;
cout << "Balance: " << balance << endl;
return 0;
}
Step-by-step explanation:
Answer in c++
#include <iostream>
using namespace std;
int main()
{
const double RATE = 5;
const double INITIAL_BALANCE = 10000;
const double TARGET = 2 * INITIAL_BALANCE;
cout << "Annual contribution: " << endl;
double contribution;
cin >> contribution;
double balance = INITIAL_BALANCE;
int year = 0;
// Add annual contribution, but not in year 0
while (balance < TARGET){
year++;
balance = balance * (1 + RATE/100) + contribution;
}
balance = balance - contribution;
cout << "Year: " << year << endl;
cout << "Balance: " << balance << endl;
return 0;
}