472,371 Members | 1,535 Online

# Trying to figure a Banking Program

I'm working on a program that will compute interest on a savings
account. The interest is compounded monthly for 30 years, and a
desposit is made on the account at the beginning of each year. My
problem is that my C++ skills are pretty limited, and this needs to be
done within a few days. I've figured out a basic structure, but need
help understanding what is and what is not working. Here's what I've
got so far:

#include <iostream>
using namespace std;

int main()
{
double I, P, R;
int i, x;

P=2000.00;
R=00.06;

{
for (i=0; i<30; i++)
{
for (x=0; x<12; x++)
I=P+P*R;

cout<< i << " "<< I<<endl;
i++2000.00;
}
}
return 0;
}

I know that I have to use a nested loop at some point, but I'm not sure
if I set it up correctly. I also realize that this is pretty barebones
in terms of actual programming, as I'm not an expert and trying to keep
this as simple for myself as possible. Any advice would be extremely

Feb 11 '06 #1
2 2963
<ja*******@hotmail.com> wrote:
I'm working on a program that will compute interest on a savings
account. The interest is compounded monthly for 30 years, and a
desposit is made on the account at the beginning of each year. My
problem is that my C++ skills are pretty limited, and this needs to be
done within a few days. I've figured out a basic structure, but need
help understanding what is and what is not working. Here's what I've
got so far:

#include <iostream>
using namespace std;

int main()
{
double I, P, R;
int i, x;

P=2000.00;
R=00.06;

{
for (i=0; i<30; i++)
{
for (x=0; x<12; x++)
I=P+P*R;

cout<< i << " "<< I<<endl;
i++2000.00;
}
}
return 0;
}

I know that I have to use a nested loop at some point, but I'm not sure
if I set it up correctly. I also realize that this is pretty barebones
in terms of actual programming, as I'm not an expert and trying to keep
this as simple for myself as possible. Any advice would be extremely

Nothing leaps out at me as being terribly wrong with what you have. But
since the indentation got lost somewhere it's a bit hard to look at. I am a
great believer in using a lot of functions, even for trivial things. I
would write two functions, one to credit the interest every month and
another to add to the principal every year. main would just manage the
process. Note that many nested loops disappear, as if by magic, when this
is done. Using a pidgin pseudocode main would be something like::

for(int year =0; year<30; year++)
do_something
for(int month =0; month<12; month++)
do_something else
Feb 11 '06 #2

<ja*******@hotmail.com> wrote in message
I'm working on a program that will compute interest on a savings
account. The interest is compounded monthly for 30 years, and a
desposit is made on the account at the beginning of each year. My
problem is that my C++ skills are pretty limited, and this needs to be
done within a few days. I've figured out a basic structure, but need
help understanding what is and what is not working. Here's what I've
got so far:

#include <iostream>
using namespace std;

int main()
{
double I, P, R;
int i, x;

P=2000.00;
R=00.06;

{
for (i=0; i<30; i++)
{
for (x=0; x<12; x++)
I=P+P*R;

cout<< i << " "<< I<<endl;
i++2000.00;

i++2000.00; does not compile for me.

Did you mean i+= 2000.00; and if so, why are you tring to add 2000.00; to
your for counter? Did you mean I? So I += 2000.00; ? And if so, why would

If this 2000.00 is deposited every year, isnt' it the Principal that
increases? So wouldn't it be
P += 2000.00;
?

Okay...

I = P + P*R;
Principal * Rate. So a few things gotta be fixed.

#include <iostream>

double Dollars( const double& Amount )
{
return ( static_cast<float>( static_cast<int>( Amount * 100.00 ) ) /
100.00 );
}

int main()
{
double I, P, R;
int y, m;
P = 0.0;
R = 00.06 / 12.00;
for (y = 0; y < 30; y++)
{
std::cout <<"Principal:" << P << " *** Deposit ***:" << 2000.00 << "
New Balance:" << P + 2000.00 << std::endl;
P += 2000.00;
for (m = 0; m < 12; m++)
{
I = Dollars( P * R );
std::cout << "Year:" << y + 1 << " Month:" << m + 1 << "
Principal:" << P << " Interest:" << I << " New Balance:" << P + I <<
std::endl;
P += I;
}
std::string wait;
std::getline( std::cin, wait );
}
std::string wait;
std::getline( std::cin, wait );
return 0;
}

Notice I changed i and x to y and m for Year and Month. Myself, I would go
ahead and use Year and Month as the counters themselves. Gets rid of the
type of confusion you had. Also, I doubt highly if the bank is going to
give you 6% monthy interest. That's 72% yearly interest not even
compounded. So each month one way to calculate it is to simply divide the
yearly rate by 12. Like I said, one way, different loans, even "simple
interest" are calculated different ways sometimes. This one is just common.
So, your monthly interest is 6% divided by 12 months, or 00.06 / 12.

Also, I gave a few more columns so you could see what was going on.

Also, I included a Dollars function. The reason being, the bank doesn't
give you half pennies, it drops them.

Also, changed the payments to the beginning of the year, not the end. Why?
Because otherwise you have 31 payments of 2000 instead of 31 (one at the
very end of the term).

I tested this and it looks somewhat right. The last line I see is:

Year:30 Month:12 Principal:172045 Interest:860.22 New Balance:172905
Feb 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

### Similar topics

 2 by: Gill Bates | last post by: I'm trying to login to a banking site (https://www.providentconnection.com) using vb.net. I've tried many variations of WebClient and HttpWebRequest; none of which I've got to work. My latest... 13 by: ashu | last post by: hi to all, Please read the following ques. first. assume that a bank maintains 2 kinds of accounts for customers one called as savings accounts & other as current account. the savings account... 3 by: mazubair | last post by: I am going to develop a Banking Solution for very small branches of a Bank. The branches are standalone and no remote transactions will be made i.e. only the individual branch will be under... 0 by: jason1551 | last post by: I'm working on a program that will compute interest on a savings account. The interest is compounded monthly for 30 years, and a desposit is made on the account at the beginning of each year. My... 11 by: cj | last post by: Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding... 5 by: Jervin | last post by: Project Requirements The key elements of the project are that the project: • Needs a database support. • Have rather well defined functions with certain degree of complexity. ... 2 by: techgirl | last post by: Hi All- I was wondering if anyone could help me with this issue. I am trying to run this 3rd party application called "CoreFTP.exe" from within C#. I have tested my code with "Notepad.exe" and... 8 by: lifeisgreat20009 | last post by: What might be the possible cause ? I have created a website using struts framework, jsp In my transaction page the money is not getting transferred.. When I hit the submit button in my... 1 by: zacharyrs | last post by: So I've made easy math programs with C before, but my task at hand is a bit complex for where my knowledge is at the moment. I need to take the calculator found here (calculator:... 2 by: Kemmylinns12 | last post by: Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies... 0 by: Naresh1 | last post by: What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle... 0 by: antdb | last post by: Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and... 1 by: Matthew3360 | last post by: Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a... 0 by: Oralloy | last post by: Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++... 0 by: Carina712 | last post by: Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important... 0 by: Rahul1995seven | last post by: Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts... 2 by: Ricardo de Mila | last post by: Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what... 1 by: Johno34 | last post by: I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...