retirement program

hello all. my task is to write a program that asks the user:

how much money they will save per month
what annual interest rate they hope to earn
how many months to calculate compound interest
what the savings target is (e.g. a million dollars)

my program will then output a month-by-month summary that shows:

how many months the user has been saving money
how much money the user deposited this month (principal)
the total amount of money deposited (principal)
the total amount of money saved (principal and interest)

Once this table of information is printed, your program should print out how many months it took to reach the savings target. If the target is not reached, your program should print out a message like "Sorry, savings target not reached".

now... all that being said, im not asking and i dont want you to write the entire program. (i dont want you to think im "one of those guys").

the issue im trying to figure out is how to add up the total invested for each month.

the second issue i cant figure out is why my collumn "dep this month" is adding up by 1.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>  
#include <iomanip>
using namespace std;  
int main()  
{

  int number=1;
    
    //asking the user how much money they will save per month 
    
    float save = 1;
    
    do
    {
    cout<< " How much money will you save/month?  ";
    cin>> save;
    }
    while( save <= 0);

    //asking the user what interest rate they hope to earn
    
    float interest = 1;
    do
    {
    cout<< " What interest rate do you hope to earn?  ";
    cin>> interest;
    }
    while( (interest < 0) || (interest > 100));

    //asking the user how many months to calculate compound interest

    float months = 1;
    do
    {
    cout<< " How many months do you want to save for  ";
    cin>> months;
    }
    while(months <= 0);

    //asking the user what the savings target is (e.g. a million dollars)

    float target = 1;
    do
    {    
    cout<< " What is your savings target?  ";
    cin>> target;
    }
    while(target <= 0);

    //print out the junk

    cout<< setprecision(0) << fixed << "months\tdep.this month\ttotal deposited\ttotal saved\n";
    
    while(number <= months) 
    {
    cout<< number++;
    cout<< "\t"<<save;
    cout<<"\t"<<save++<<endl;
    }
    /*Your program will then output a month-by-month summary that shows:
    how many months the user has been saving money
    how much money the user deposited this month (principal)
    the total amount of money deposited (principal)
    the total amount of money saved (principal and interest)*/
system("pause");
}
I find it helpful to take some actual values and try to simulate the calculations by hand. For example, use a monthly deposit of $100 with an annual interest rate of 12%. Using these numbers, try to work out how much was saved for each of the first three months.
thanks for the reply squished18. im sorry, i was unclear in my original question. i am having issues formatting the program with respect to the columns. i have formatted the months, but i cant seem to figure out how to consecutively add the total deposited each month.
the issue im trying to figure out is how to add up the total invested for each month.

You need a running total variable.
1
2
3
4
5
6
  float total = 0;

  //  After line 55: 
  total += save;  //  Add amount saved to the running total
  //  After line 58
  cout << '\t' << total;

Note: The above code does not consider interest earned per month.

the second issue i cant figure out is why my collumn "dep this month" is adding up by 1.

Line 58: You're incrementing save by 1 each time through the loop.





Topic archived. No new replies allowed.