473,796 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
helpful and appreciated.

Feb 11 '06 #1
2 3090
<ja*******@hotm ail.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
helpful and appreciated.


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*******@hotm ail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
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
you add 2000.00 to your interest?

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

But, your Interest, I you are already adding the princpal into I see.
Okay...

I = P + P*R;
That makes your Interest equal to Your Principal plus your prinicpal times
rate. Wrong. Your PRINCIPAL becomes your Principal + Interest, which is
Principal * Rate. So a few things gotta be fixed.

#include <iostream>

double Dollars( const double& Amount )
{
return ( static_cast<flo at>( 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:17204 5 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
2322
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 version is: Dim myWebClient As New WebClient Dim nvc As New NameValueCollection nvc.Add("Login", username) nvc.Add("Password", password)
13
2784
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 provides simple interest & withdraw facilities but no check book facilities. the current account provides check book facilities but no interest.
3
5472
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 networking and there will be no networking between the branches. The branches have maximum 10000 (ten thousand) customer accounts, maximum 200 daily (60000 yearly) transactions and maximum 3 to 4 concurrent users. The solution will provide voucher...
0
372
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 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>...
11
6659
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 seems to be done like this 3.435 = 3.44 3.445 = 3.44 Dim decNbr1 As Decimal
5
4485
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. Implementation Requirement (Functional System)
2
3023
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 that opens up fine. I've tried it with another program executable and it works as well. When I go to run coreftp.exe, it will not work. I have even tried putting code into a .bat file and trying to execute that and it executes, but I get the same...
8
2683
lifeisgreat20009
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 Transaction.jsp page , no transaction happens .. Only the url changes from http://localhost:8080/bankfinalproject/jsp/transaction.jsp to this
1
2089
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: http://ohts.wustl.edu/risk/calculator.html, appendix which covers it a bit: http://ohts.wustl.edu/risk/formula.html) and program it into a ObjC program. I'm having a hard time trying to figure out the weight/formula for this. Hoping to find help in the right...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10465
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
10242
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
10200
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
7558
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
6800
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
5453
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
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
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.