Basic C++ help: This is what it is asking. Ask the user for an amount to save ea
ID: 3925086 • Letter: B
Question
Basic C++ help: This is what it is asking.
Ask the user for an amount to save each month. Assuming a 1% per month interest rate, how many MONTHS will it take the user to save $1000. Add the savings at the END of each month. For example:
This is what I have so far, but it keeps timing out so I don't think I have the math or loop set up correctly.
#include <iostream>
#include <string>
using namespace std;
int main() {
double amount = 0.0;
double interestTotal = 0.0;
double interest = 0.01;
double total = 0.0;
int months = 0;
cout << "How much do you want to save each month?: ";
cin >> amount;
cout << amount;
do {
interestTotal = (total + amount) * interest;
total += amount + interestTotal;
cout << "Month " << months + 1 << ": $" << interestTotal << " deposited " << amount << " interest earned is " << total;
months++;
}
while (total <= 1000);
cout << "It took " << months << " months, and you now have $" << total << endl;
return 0;
}