- #1
MMOne
- 3
- 0
Hello everyone!
I am very new to programming and am beginning to struggle in studies.
I have been working on this same problem for about 5 hours and cannot for the life of me get this thing to compile correctly. Any assistance or guidance for what I should do would be greatly appreciated.
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.
The outcome doesn't add the interest on the first month but waits for the second and messes up total count calculations.
I am very new to programming and am beginning to struggle in studies.
I have been working on this same problem for about 5 hours and cannot for the life of me get this thing to compile correctly. Any assistance or guidance for what I should do would be greatly appreciated.
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.
Code:
#include <iostream>
using namespace std;
int main (){
const double interest = 0.01;
int deposit = 0;
int months = 0;
double totalSaved = 0.0;
double interestEarned = 0.0;
cout << "How much do you want to save each month? ";
cin >> deposit;
cout << deposit << endl;
while (totalSaved <= 1000){
++ months;
interestEarned = totalSaved * interest;
cout << "Month " << months << ": $" << totalSaved;
totalSaved = totalSaved + interestEarned;
cout << " deposited " << deposit << " interest earned is " << interestEarned << endl;
if (totalSaved >= 1000){
cout << "It took " << months << " months, and you now have $" << totalSaved << endl;
}
}
return 0;
}
The outcome doesn't add the interest on the first month but waits for the second and messes up total count calculations.