Computing the number of months to save $1000

  • MHB
  • Thread starter MMOne
  • Start date
  • Tags
    Computing
In summary, the user wants to save $1000 each month for 1 year. The user will earn $90 in interest over the course of the year.
  • #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.

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.
 
Technology news on Phys.org
  • #2
Re: Computing the number of months to save \$1000

I think your problem is that you begin your calculations in the loop and don't account for initial month. I rewrote some of your program. It will also be easier to read if you put your cout statements outside of your loop so if your input is very small, it wouldn't produce like a thousand couts for 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;

    // if the deposit is already 1000 aka no looping required
    if (deposit >= 1000){
    cout << "month: " << months << endl;
    cout << "interest you earned is: " << interestEarned << "$" << endl;
    cout << "now you have: " << totalSaved << "$" << endl;
    }
    // initial interest earning calculations
    interestEarned = deposit * interest;
    totalSaved = deposit + interestEarned;
    // looping for total saved
    while (totalSaved <= 1000){
        interestEarned = totalSaved * interest;
        totalSaved = totalSaved + interestEarned;
        months++;
    }
    // couts for how much you earned in how long
    cout << "month: " << months << endl;
    cout << "interest you earned is: " << interestEarned << "$" << endl;
    cout << "now you have: " << totalSaved << "$" << endl;
    return 0;
}
 
Last edited:

1. How do I calculate the number of months it will take to save $1000?

The formula for calculating the number of months it will take to save $1000 depends on your monthly savings amount and the interest rate on your savings account. You can use a financial calculator or an online savings calculator to determine the exact number of months.

2. What is the average amount of time it takes to save $1000?

The average amount of time it takes to save $1000 varies depending on individual saving habits and financial situations. However, according to a study by Bankrate, it takes the average American about 5 months to save $1000.

3. How can I speed up the process of saving $1000?

To speed up the process of saving $1000, you can increase your monthly savings amount, find ways to cut expenses, or look for ways to earn extra income. Additionally, you can consider putting your savings in a high-interest savings account, which will earn you more interest over time.

4. Is it better to save a lump sum or make monthly contributions to reach $1000?

It depends on your financial situation and personal preference. Saving a lump sum may be more challenging for some people, while others may find it easier to save smaller amounts each month. However, making monthly contributions is generally a more sustainable and consistent approach to reaching a savings goal.

5. What are some tips for staying motivated while saving for $1000?

One way to stay motivated while saving for $1000 is to set small milestones and celebrate each time you reach them. You can also create a budget and track your progress to see how far you've come. Another tip is to keep your end goal in mind and remind yourself of why you are saving $1000 in the first place.

Similar threads

  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
Replies
10
Views
960
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
6
Views
8K
  • Programming and Computer Science
Replies
23
Views
2K
  • Programming and Computer Science
2
Replies
66
Views
4K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
23
Views
1K
  • Programming and Computer Science
2
Replies
36
Views
2K
Back
Top