Compound Interest rates problem.

Hi guys. Im having an issue with my compound interest rate program. I need Im study on the counting loops each day part. I want it to show the new intrest rate each day for however long the user says. Also need it to show how much they saved. Feel free to make any changes you like.

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
#include<iostream>
#include<assert.h>

using namespace std;

int main()
{
    int startingbalance, countbalance, newbalance, days;
    float intrest, rate;
    
    //Enter starting balance. Loop until greater startign balance greater than 0.
    do
    {
        cout<< "Please enter starting balance: ";
        cin>> startingbalance;
    }
    while (startingbalance<0);
    
    //Enter intrest rate. Loop until its greater than 0. Assert if 2.0 or greater.
    do
    {
        cout<< "Enter intrest rate in decimal form: ";
        cin>> intrest;
    }
    while (intrest<0);
    assert (intrest<2.0);
    
    //Enter how many days. Loop until days is greater than 0. Assert if days greater than 1000.
    do
    {
        cout<< "Enter number of days: ";
        cin>> days;
    }
    while (days<0);
    assert (days<1000);
    
    countbalance=0;
    while(countbalance < days)
    {
        newbalance = (startingbalance * (1+rate/365));
        countbalance = countbalance +1;
    }
    
    cout << "your new balance is "<< newbalance <<endl;
    
    system("pause");
    return 0;
}
I'm not positive I understand what you're asking - I think you mean that the user has a balance of X and an interest rate of #.# and you want to output the daily balance for N number of days, assuming that the interest is compounded daily? Or is it something else?

line 40 - rate has no value when you try to add 1 to it here
Yes thats exactly what I want but I'm stuck. What should I change/add.
Last edited on
Topic archived. No new replies allowed.