473,805 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formula for calculating annual interest

4 New Member
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 "TotalamountFin al".
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
4 8777
r035198x
13,262 MVP
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 "TotalamountFin al".
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 TotalamountFina l supposed to be?
Isn't it just the final value of Initialstatemen t in your loop?
Sep 25 '06 #2
Veger
4 New Member
I would LIKE TotalamountFina l to be the interest accumulated for the set # of years "Numberofye ars" (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
Veger
4 New Member
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 Initialstatemen tTWO
?
Sep 25 '06 #4
Veger
4 New Member
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 Initialstatemen tTWO equivalent to Initialstatemen t.

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

So, I thought I"d make initialstatemen t equal to another variable, then use THAt variable "Initialstateme ntTWO to calculate interest over time in the loop.

Apparently, I can't do this because its' not recognizing initialstatemen tTWO as being equal to Initialstatemen t when I say
Initialstatemen t = Initialstatemen tTWO.

Any ways around this?
Sep 25 '06 #5

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

Similar topics

7
2185
by: JLM | last post by:
I have a table that has fieldA, fieldB, fieldC. I want fieldC=fieldA-fieldB. simple enough. the next record I want to be able to do the same on the new value of fieldC. I can do this with SAP ABAP/4, but have never done this using Access. I'm sure this can be done, but not sure how to go about it. thanks in advance, jlm
1
2380
by: jlm | last post by:
I have a form which feeds table (TblEmpLeave) of Employee Leave Time (time taken off for Administrative, Annual, Sick, Compensation leave). I have EmpID, LeaveDate, LeaveType, LeaveHours fields on this form. Any employee can have multiple entries in the table (key fields are EmpID and LeaveID) for multiple dates (John Doe can take 3 days annual leave, then take 3 days sick leave in any given month. I have a BeginningBalance of hours that...
0
1739
by: Jason | last post by:
I need help designing a query (or two) in MS Access that will calculate a compounded rate of interest. This would be no problem using a simple FV function if the Interest Rate were constant. Unfortunately the Interest rate changes through time. Whenever a new interest rate period begins, I need to calculate the interest for the new period using the ending balance from the previous interest rate period. See example below. Unfortunately,...
2
2089
by: chrisb1586 | last post by:
Hey guys I have no idea with what im doing with loops( a for, do, or while loop any of the 3) or the logic on how to do this and i have to have this done for school tommorow. I have to create a windows app with 4 text boxes for starting balance, number of years, interest rate %, and what you will have which is a read only. One calculate button to do this all. heres what i have now all and any help is much appreciated thanks because i really...
2
1390
by: lab3terch | last post by:
I am working on a program in which the user enters an amount of money in a textbox, selects a beginning and ending date using the datetimepicker, and then the program calculates the new amount based on an interest rate of 1% compounded monthly. The code I have written is as follows: Public Class Form1 Private Sub cmdCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCompute.Click Dim amount As...
3
13770
by: debi.robarts | last post by:
I am setting up a database to keep track of network leases. I have a field for "original rent" and then fields to capture how it escalates (what % how often). I want to set up fields that give 1) the current rent and 2) what the rent will be at next escalation. Is there a way to make Access calculate compounded interest? For example: Original rent is $100
8
2094
by: teddarr | last post by:
I'm having trouble getting a mathmatical formula to work in my code. I am supposed to write a program in java that calculates the ending balance each month. The user is supposed to input the monthly payment, the annual interest rate, and the total months required to pay off the loan. I am to use the formula: Balance(pn) = payment * (1 - (1 + mir) ^ (pn - tp)) / mir payment = monthly payment mir = monthly interest rate
2
5432
by: mastern200 | last post by:
I need to make a program that calculates Compound Interest (compounded monthly). Thing is, it has to use recursion. I don't know how to implement it in though. This is the code i have so far. #include<iostream> #include<cstdlib> using namespace std; float initialDeposit=0; int depositMonth=0; float interestRate=0;
10
11604
by: Joseph Geretz | last post by:
I need to calculate miles per degree longitude, which obviously depends on latitude since lines of longitude converge at the poles. Via Google, I've come up with the following calculation: private const double MilesPerDegLat = 69.04; private const double EarthRadiusMiles = 3963.1676; private static double PiDiv180 = Math.PI / 180; double MilesPerDegLon = MilesPerDegLat * Math.Cos(Latitude * PiDiv180)
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10613
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.