By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 1,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

Formula for calculating annual interest

P: 4
I'm having some logic trouble (IE: I can't figure out how to do this)
I have an assignment in which I need to calculate annual interest.
IE:

P1 = P0 + P0*INT (interest) = P0*(1+INT)
P2 = P1 + P1*INT = P1*(1+INT) = P0 * (1+INT) * (1+INT) = P0 * (1+INT)^2
P3 = P2 + P2*INT = P2 *(1+INT) = P0 * (I+INT)^3

And so on.

essentially, here is what I have so far.
\*Notes
The initial statement is supposed start at 1700, it's supposed to compound for 60 years, and it has to be a 10% interest rate.
*\
Expand|Select|Wrap|Line Numbers
  1. # include <iostream>
  2. # include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main (int argc, char* argv[])
  7. {
  8.     int i; // counter
  9.     double Initialstatement = 1700;
  10.     int    Numberofyear = 60;
  11.     double Interest = 0.1;
  12.     double Totalamountyr;
  13.     double TotalamountFinal;
  14.  
  15.  for (i = 0; i < Numberofyear; i++)
  16.         {
  17.              Initialstatement = Initialstatement * Interest + Initialstatement;
  18.              TotalamountFinal = Initialstatement + (Initialstatement * Numberofyear);
  19.              }
  20.         cout << fixed << showpoint;
  21.         cout << setprecision(2);
  22.         cout << TotalamountFinal << "\n";
  23.  
  24.         system ("PAUSE");
  25.         return 0;
  26. }
This doesn't really do the correct math for "TotalamountFinal".
Instead of acquiring interest from the previous year each year and adding it, it goes off in the wrong direction the minute i = 1 (or more than 1 year for the # of years)

So, how can I set this up using loops, and not using powers?
My professor won't let me use power functions.
Sep 25 '06 #1
Share this Question
Share on Google+
4 Replies


10K+
P: 13,264
I'm having some logic trouble (IE: I can't figure out how to do this)
I have an assignment in which I need to calculate annual interest.
IE:

P1 = P0 + P0*INT (interest) = P0*(1+INT)
P2 = P1 + P1*INT = P1*(1+INT) = P0 * (1+INT) * (1+INT) = P0 * (1+INT)^2
P3 = P2 + P2*INT = P2 *(1+INT) = P0 * (I+INT)^3

And so on.

essentially, here is what I have so far.
\*Notes
The initial statement is supposed start at 1700, it's supposed to compound for 60 years, and it has to be a 10% interest rate.
*\
Expand|Select|Wrap|Line Numbers
  1. # include <iostream>
  2. # include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main (int argc, char* argv[])
  7. {
  8.     int i; // counter
  9.     double Initialstatement = 1700;
  10.     int    Numberofyear = 60;
  11.     double Interest = 0.1;
  12.     double Totalamountyr;
  13.     double TotalamountFinal;
  14.  
  15.  for (i = 0; i < Numberofyear; i++)
  16.         {
  17.              Initialstatement = Initialstatement * Interest + Initialstatement;
  18.              TotalamountFinal = Initialstatement + (Initialstatement * Numberofyear);
  19.              }
  20.         cout << fixed << showpoint;
  21.         cout << setprecision(2);
  22.         cout << TotalamountFinal << "\n";
  23.  
  24.         system ("PAUSE");
  25.         return 0;
  26. }
This doesn't really do the correct math for "TotalamountFinal".
Instead of acquiring interest from the previous year each year and adding it, it goes off in the wrong direction the minute i = 1 (or more than 1 year for the # of years)

So, how can I set this up using loops, and not using powers?
My professor won't let me use power functions.
What is TotalamountFinal supposed to be?
Isn't it just the final value of Initialstatement in your loop?
Sep 25 '06 #2

P: 4
I would LIKE TotalamountFinal to be the interest accumulated for the set # of years "Numberofyears" (which = 60).
IE:
Initial Amount*(1+INT)^60
or
1700*[(1+ .1)^60]

Problem is, I don't know how to do this without USING powers (which I can't use)
I need to find another way of mathematically calculating it out...
Without typing each of the 60 lines for each year. Because the # of years will eventually be something I allow the user to choose. First I need to get the math right.
Sep 25 '06 #3

P: 4
Ok, FORGET MY LAST QUESTION, I've revamped my code and this is what I've got.
I have a totally new question that's probably easier to answer.

I didn't put all the code, just what's essential for this question, so there might be some extra ints and doubles you don't understand.
Should still be easy to figure out.

Expand|Select|Wrap|Line Numbers
  1. # include <iostream>
  2. # include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main (int argc, char* argv[])
  7. {
  8.     int i; // counter
  9.     double Initialstatement;
  10.     double InitialstatementTWO;
  11.     int    Agestart;          // Age you start at
  12.     int    AgeWithdraw;       // Age you withdraw money from
  13.     int    Numberofyear;      // The Number of years Interest will be calcualted
  14.     int    Numberofyearplus;  // The Number of years plus 1
  15.     double x;
  16.     double y;
  17.     double Interest = 0.1;    // interest rate
  18.     double Interestperyear;   // The amount of interest per year gained off of 61 years
  19.  
  20.     cout << "What is the Age of the individual when the initial amount \n"
  21.          << "is deposited? \n";
  22.     cin >> Agestart;
  23.  
  24.     cout << "What is the Age of the individual when the money will be \n"
  25.          << "withdrawn? \n";
  26.     cin >> AgeWithdraw;
  27.  
  28.     Initialstatement == InitialstatementTWO;
  29.     Numberofyear = AgeWithdraw - Agestart;
  30.     cout << "Interest will be calculated for " << Numberofyear << " years.\n";
  31.     cout << "\n";
  32.     cout << "What is the initial statement to be deposited?\n";
  33.     cin >> Initialstatement;
  34.  
  35.  
  36.     for (i = 0; i < Numberofyear; i++)
  37.         {
  38.  
  39.            InitialstatementTWO = InitialstatementTWO * Interest + InitialstatementTWO;
  40.           }
  41.        cout << fixed << showpoint;
  42.         cout << setprecision(2);
  43.         cout << InitialstatementTWO << "\n";
  44.         system ("PAUSE");
  45.         return 0;
  46. }
So the question is...

Why do I get a "0.00" for InitialstatementTWO
?
Sep 25 '06 #4

P: 4
I think the problem lies here.

Expand|Select|Wrap|Line Numbers
  1.     cout << "What is the initial statement to be deposited?\n";
  2.     cin >> Initialstatement;
  3.     Initialstatement = InitialstatementTWO;
  4.  
  5.     for (i = 0; i < Numberofyear; i++)
  6.         {
  7.  
  8.            InitialstatementTWO = InitialstatementTWO * Interest + InitialstatementTWO;
  9.         }
I need to find a way to make InitialstatementTWO equivalent to Initialstatement.

initialstatement will change in the loop over time, but I need to refer to the original " cin >> Initialstatement" and output it for the assignment.

So, I thought I"d make initialstatement equal to another variable, then use THAt variable "InitialstatementTWO to calculate interest over time in the loop.

Apparently, I can't do this because its' not recognizing initialstatementTWO as being equal to Initialstatement when I say
Initialstatement = InitialstatementTWO.

Any ways around this?
Sep 25 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.