Looping problem

Im working on an assignment and having trouble with it. The code I have so far is written below. Im confused about how to have a user cin an initial amount, cin an interest amount, and update each year (1-10) a total earned off of that interest. I have been trying at this for some time now and would like any hints or suggestions so I can finish this. I was thinking I needed a nested loop but that wasnt working.

1
2
3
4
5
6
7
8
9
10
11
//     For example, if the initial amount is $1000 with an interest rate of 6.5%,  
//     the output should be the following.
//
//
//         Year                   Balance
//         ______                  _______
//           1                     1065.00
//           2                     1134.22 
//           3                     1207.94
//           .                       .
//           .                       . 

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
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
   int amount;
   double interest;
   double balance;
   double per; 
   cout << "What is the initial amount in the account?  ";
   cin >> amount;
   cout << "What is the interest rate?  ";
   cin >> interest;
  
   
        
   cout << "Year" << "\t\t" << "Balance" << endl;
   cout << "____" << "\t\t" << "_______" << endl;
   
   
   for (int i = 1; i <= 10; i++)
   {
       cout << i << "\t\t" << balance << endl; 
       
   }

system("pause");
return 0;
}        

Last edited on
you are almost done

do you know the formula for compound interest?

do you know the equivalent C/C++ formula for compound interest?
A = P(1 + r/n)^nt i think.

I do not know the formula equivalent. Even if I use it, im not sure exactly how to implement it to complete the "Balance" column shown above in the example.
well, you just showed me the formula - there is no ^ in C/C++ - you will have to use pow() from math.h instead:

http://www.cplusplus.com/reference/clibrary/cmath/pow/

do you really understand the formula or are you just copy-pasting?

the answer to your question is right in that formula! (hint: balance maps to one of those symbols in your formula)
closed account (yUq2Nwbp)
but where you initialized your balance??
I knew the formula... I guess to be honest with you I just didnt think about using it. I know there is no "^" and that the #include <cmath> needs to be used for pow. Im not sure what you meant in your hint though.
hope this helps

#include <iostream>
// #include <fstream>

using namespace std;

int main()
{
// int amount;
double interest;
double balance;
// double per;
cout << "What is the initial amount in the account? ";
cin >> balance;
cout << "What is the interest rate? ";
cin >> interest;



cout << "Year" << "\t\t" << "Balance" << endl;
cout << "____" << "\t\t" << "_______" << endl;

for (int i = 1; i <= 10; i++)
{
balance += (interest/100)*balance;
cout << i << "\t\t" << balance << endl;

}

system("pause");
return 0;
}
Topic archived. No new replies allowed.