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

Home Posts Topics Members FAQ

Trying to do a compounded interest program

Im trying to get the compounded interest to go back only being
compounded annually. I want the user of this program to be able to do
semi annually of monthly or some other.

This is my code. Any input is welcome

int main()
{
double a,b,c,d,e;//a is amount to be invested, b is years invested
//c is compound time, d is interest rate, e is the final ammount
char ch;//allows user to enter another investment
do{
system("cls");
cout<<"enter an ammount to invest ";
cin>>a;
cout<<"Enter the years to allow to mature ";
cin>>b;
cout<<"How many times a year will it be compounded? ";
cin>>c;
cout<<"What is the rate ";
cin>>d;

for(int i=0;i<b;i++){
a=a+(a*(d/100));
e=pow(a,c);
}

cout<<"After "<<b<<" years. You have now "<<e<<" dollars in the
account\n";

cout<<"Would you like to run another? ";
cin>>ch;
}while(ch=='y'| |ch=='Y');

return 0;
}

Dec 14 '06 #1
1 2364

"Drakscon" <dr****@netscap e.netwrote in message
news:11******** **************@ 80g2000cwy.goog legroups.com...
Im trying to get the compounded interest to go back only being
compounded annually. I want the user of this program to be able to do
semi annually of monthly or some other.
Then you need the user to be able to select the formula they want
>
This is my code. Any input is welcome

int main()
{
double a,b,c,d,e;//a is amount to be invested, b is years invested
//c is compound time, d is interest rate, e is the final ammount
char ch;//allows user to enter another investment
do{
system("cls");
cout<<"enter an ammount to invest ";
cin>>a;
cout<<"Enter the years to allow to mature ";
cin>>b;
cout<<"How many times a year will it be compounded? ";
cin>>c;
cout<<"What is the rate ";
cin>>d;

for(int i=0;i<b;i++){
a=a+(a*(d/100));
e=pow(a,c);
This is your formula. Which will change for differnt types of interest.
What I would do is either make this a function or put it in a class (since
it is c++) then select the appropriate function depending on the users
input. Something like:

double SimpleInterest( double Amount, double Years, double Times, double
Rate )
{
double Balance
for (int i=0; i < b; i++ )
{
Amount = Amount + (Amount * ( Rate / 100.0 ));
Balance = pow(Amount, Times);
}
}

(Note, I don't know if your formula is right)

Then you can:

double Balance = SimpleInterest( a, b, c, d );
You REALLY need to pick better variable names. a, b, c and d are
meaningless. See I used what they actually are.

Anyway, have the user select the type of interest they want then either use
an if else block or switch statement.

double Balance = 0;
if ( Type == "S" ) // Simple Interest
Balance = SimpleInterest( a, b, c, d );
else if ( Type == "C" ) // Compound interest
Balance = CompoundInteres t( a, b, c, d );
else if ( ... yada yada )
else
std::cout << "Unknown interest type";

Or whatever.

Of course you'll need to make different functions with the right math for
each type of interest.
>

}

cout<<"After "<<b<<" years. You have now "<<e<<" dollars in the
account\n";

cout<<"Would you like to run another? ";
cin>>ch;
}while(ch=='y'| |ch=='Y');

return 0;
}

Dec 14 '06 #2

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

Similar topics

4
5024
by: ulysses | last post by:
hi, I'm working in python 5 months. I think it's very cool language. I do a p2p python program GUI. First I make a software by wxpython. But I find wxpython use many many memory. Second I use PYQT. But memory use still big. But but but when I minimize the windows to taskbar, a fantasy something happened. memory use very very low when windows minimize.
0
1737
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,...
5
16968
by: Good Man | last post by:
Hi there I am trying to execute a custom-built java program on my linux server via PHP. Basically, a user uploads files via PHP, and then the java program performs some action on these files. I have successfully had other operations performed on these files by using backticks, ie: $doit = `my exec command`;
2
3090
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>...
4
8776
by: Veger | last post by:
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.
2
4335
by: fatimahtaher | last post by:
Hi, I am new to C# programming and my first assignment requires me to calculate total interest paid on a loan. The user will input the loan, the interest rate per month, and the monthly payment. It has to use a while loop and calculate the following: Total amount of interest paid and the number of months to pay off the loan. I am not a finance major so I have some difficulty with the logistics of how to go about doing this. My code so...
1
1422
by: enert | last post by:
I am writing a project for class computing simple interest. The program compiles so I know my syntax is correct. My logic looks correct but its not giving me the correct answers. I think it has something to do with my specifications of the type of input. What kind of input (i.e. %d,%f,%lf,%Lf) would I use if the input such as interest was a simple decimal numer such as 0.0835? I'm not looking for the solution... just some help, figuring this...
24
3709
by: jerrydigital | last post by:
Hello, I am new to this forum but have read several posts and I thank you for your great assistance. I am stumped right now. I have a user registration form in asp that is set to a form method=registration.asp page. i will post my registration.asp page below. I am hoping this asp page will connect to my access database called registration.mdb with a table called registration. however, everytime i submit my registration information, I...
2
2948
by: fury30 | last post by:
this is the program as below and now what i need to do is add the following to it but i am not able to get how to do it # futval.py # A program to compute the value of an investment # carried 10 years into the future def main(): print "This program calculates the future value" print "of a 10 year investment."
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
9535
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
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...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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();...
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.